var common = {

    //是否禁言(默认没有禁言)
    userBan: false,
    classBan: false,
    userBanId: 0,
    //聊天内容只显示老师内容
    teacherMode: false,
    //在线人数
    onlineCount: 0,
    //当前网络类型
    iswifi:true,
    //默认播放视频而不是音频(1 纯音频，2 视频下的音频)
    playKind: 0,
    //视频开始播放中
    classPlaying: false,
    //网络连接正常
    conNormal: true,
    //当前系统时间(getway)
    curSysTime: 0,
    //课程开始时间(后台)
    openClassTime: 0,
    //用户ID
    userId: 0,
    //老师ID
    teacherIds: 0,
    teaLeaveTime:0,
    teaEnterTime:0,
    //助教ID
    helperId: 0,
    //渠道号
    qudaoNum: 10000,
    //教室最大容量
    teaCapacity:1000,
    peakNotice:false,
    inter: null,
    //聊天发言时间间隔
    limitSpeakTime: 0,
    //是否开启了视频(老师上课是否有视频)
    isopenVedio:1,
    //判断服务是否连接上
    IsCon:false,
    //表示课程是否结束(0表示结束)
    isClassEnd:1,
    //音频视频请求超时时间
    timeoutStr:10000,
    //超时重试请求次数
    timoutCount:0,
    //返回错误码请求次数
    errorCount:0,
    videoErrArr:["","用户终止","网络错误","解码错误","媒体资源不可用或媒体格式不被支持"],
    //聊天区内容及课堂助手的高度
    itemHeight:0,
    //默认图片路径
    imgUrl:"/static/acweb/release/images/",
    //用户及课程信息
    userAllInfo: {
        "code": 1,
        "res": {
            "roleInfo": {
                "roleId": "",
                "role": "1",
                "roleName": "",
                "qq": "",
                "skype": "",
                "pic": "",
                "cnd": ""
            },
            "meetInfo": {
                "chatSpanTime": "5",
                "pdfPath": "",
                "courseName": "",
                "appointId": "",
                "teaName": "",
                "teaId": "0",
                "teaDesc": "",
                "teaPic": "",
                "classType": 1,
                "totalPages": 1,
                "classOpenTime": 0
            }
        }
    },
    //判断音频是否可以播放的变量
    audioInfo:{

        curTime: -1,
        timePoint: 1000,
        num: 1,
        canNum: 1,
        winTimeout: null
    },

    //根据从首页得到的信息，替换当前的合局对象userAllInfo
    replaceUserInfoFun: function () {

        var res = common.userAllInfo["res"];
        var roleinfo = res["roleInfo"];
        var meetInfo = res["meetInfo"];

        roleinfo["roleId"] = $("#userIdHid").val();
        roleinfo["roleName"] = $("#userNickHid").val();

        meetInfo["pdfPath"] = $("#coursePicPathHid").val();
        meetInfo["courseName"] = $("#classTitle").html();
        meetInfo["appointId"] = $("#courseIDHid").val();
        meetInfo["teaName"] = $("#teachNameHid").val();
        meetInfo["totalPages"] = $("#coursePicCountHid").val();
        meetInfo["classOpenTime"] = $("#startTimeHid").val();

        //获取渠道号
        var qudao = $("#qudaoHid").val();
        if(qudao) common.qudaoNum  = qudao;

        //教室限制的最大容量

        var teaCountCap = $("#teaCapacityHid").val();
        if(!teaCountCap) teaCountCap = 1000;
        common.teaCapacity = teaCountCap == "999999999" ? 1000:teaCountCap;

        common.limitSpeakTime = $("#limitSpeakHid").val();

        common.isopenVedio = $("#isopenVideoHid").val();

        common.isClassEnd = $("#isOverHid").val();

        //音频模式下(没有视频)
        if(common.isopenVedio != 1){

            common.playKind = 1;
        }
    },

    //信息提示
    warnInfo: {
        moreLen: "内容过长，请分条发送",
        netWork: "请检查网络!",
        fastTime: "发言频率太快，请稍后再试",
        oneBan: "你已被禁言",
        allBan: "当前为静音模式",
        mute: "现在的课堂是静音模式，<br/>暂时无法讨论哦!",
        onlyTeachTip: "只看老师消息",
        startVdeio: "视频已开启",
        endVdeio: "视频已关闭",
        kicked: "你已经被踢出教室",
        netError: "网络异常",
        noTeaching: "没有上传教材哦",
        netWorkType: "当前是非wifi网络，确定播放视频？",
        "noKnowNetType": "未知网络类型，确定播放视频？"
    },

    //开课前时间倒计时
    countDown: function () {

        if (common.classPlaying) return;

        var timeStr = "",
            downTime=null;

        $(".jltime").show();

        var curSysTime = Number(common.curSysTime);

        if(common.inter){
            window.clearInterval(common.inter);
        }

        common.inter = window.setInterval(function () {

            var timeCha = Number((common.openClassTime - (++curSysTime)));  //时间差的秒数

            //计算相差分钟数
            if (timeCha >= 60) {

                var minutes = parseInt(timeCha / 60);

                var seconds = timeCha % 60;

                downTime = {"minutes": minutes, "seconds": seconds};

            } else {

                if (timeCha > 0)

                    downTime = {"seconds": timeCha};
                else
                    downTime = {"minutes": 0, "seconds": 0};
            }

            if (downTime) {

                if (downTime.minutes)

                    timeStr = "<em>" + downTime.minutes + "</em>分<em>" + downTime.seconds + "</em>秒";

                else
                    timeStr = "<em>" + downTime.seconds + "</em>秒";

                $("#classTimeC").html(timeStr);

                //停止微循环
                if (downTime.minutes == 0 && downTime.seconds == 0) {

                    common.classPlaying = true;

                    window.clearInterval(common.inter);

                    //开始上课
                    common.startOpenClass();

                    return;
                }
            }

        }, 1000)

    },
    //开始上课
    startOpenClass: function () {

        //清除计数器
        if(common.inter){
            window.clearInterval(common.inter);
        }

        //音频模式下
        if(common.playKind == 1){

            common.videoUrl();

            $("#zhiboing").show()
                            .siblings("span").hide();

            return;
        }

        $("#headerPage").css("display", "none !important");

        //上课时间到了，但老师没来上课，则显示老师不在的提示
        if(common.teacherIds <= 0){

            $("#intoPage").hide();
            common.showLeavePage();
            return;
        }

        //判断是否是wifi，不是则提示
        var iswifi = common.isWifiFun();

        if (!iswifi) {

            //如果没有视频，不需要提示，直接显示音频
            if(common.isopenVedio == 1){

                //金山的不显示网络提示
                if(common.qudaoNum == 10001){
                    common.showVideoTip();
                } else {
                    common.show3GPage();
                }

            } else {
                //正常显示视频
                common.showVideoTip();
            }

            common.iswifi = false;

        } else {

            //正常显示视频
            common.showVideoTip();
            common.iswifi = true;
        }

    },

    //判断是否是横屏或者竖屏
    isLandOrPort: function () {

        var phoneType = common.deviceType();

        if (phoneType == "android" || phoneType == "iphone") {

            //竖屏
            if (window.orientation == 180 || window.orientation == 0) {

                return "portrait";
            }
            //横屏
            if (window.orientation == 90 || window.orientation == -90) {

                return "landscape"
            }
        }

    },

    //顶部提示tip
    tipShow: function (str) {

        var tipBox = "<div class='tip_info_box'><div class='tip_box'>" + str + "</div></div>";
        $("body").append(tipBox);

        //自动消失
        window.setTimeout(function () {

            $(".tip_info_box").hide()
                .remove();

        }, 1000)

    },

    //得到微信浏览器代理字符串
    getAppVersion: function () {

        if (navigator.appVersion) {

            return navigator.appVersion;
        }

        if (navigator.userAgent) {

            return navigator.userAgent;
        }

    },
    //得到浏览器代理字符串
    getUserAgent: function () {

        if (navigator.userAgent) {

            return navigator.userAgent;
        }

    },
    //是微信浏览器还是其它手机浏览器
    isWeixin: function(){

        var ua = common.getAppVersion();

        // 如果是微信
        if (/MicroMessenger/.test(ua)) {

            return true;
        }
    },
    //检测用户手机类型
    deviceType: function () {

        var browerInfo = common.getAppVersion().toLowerCase();

        if (browerInfo.indexOf("android") >= 0) {

            return "android";
        }
        if (browerInfo.indexOf("iphone") >= 0) {

            return "iphone";
        }
    },

    //即登录页面成功后，获取的用户信息及课程信息
    getUserInfo: function (info) {

        common.replaceUserInfoFun();

        common.openClassTime = common.userAllInfo.res.meetInfo.classOpenTime;
        common.userId = common.userAllInfo.res.roleInfo.roleId;
        common.teacherIds = common.userAllInfo.res.meetInfo.teaId;
        common.showWhiteBoard();

    },
    //显示教材
    showWhiteBoard: function () {

        var picUrl = common.userAllInfo.res.meetInfo.pdfPath;

        if (picUrl) {

            $("#courseShow").html("<img class='img' src='" + picUrl + "'>")

        } else {

            if(common.playKind == 0){

                var noBookStr = "<div class='nobook_box'>" +
                    "<div class='m_nobook'>" +
                    "<img src='"+common.imgUrl+"nobook.png'>" +
                    "<h2>"+common.warnInfo.noTeaching+"</h2>" +
                    "</div>" +
                    "</div>";

                $("#courseShow").html(noBookStr);

            } else {

                $("#headerPage").addClass("dis-flex");
            }

        }

    },
    //16进制转化成10进制
    Converto10: function (x) {

        if (!x) return;

        var num = x.replace("0x", "");
        var result = 0;

        if (num.length >= 15) {

            result = parseInt("0x" + num.substring(3), 16);

        } else {

            result = parseInt("0x" + num, 16);
        }

        return result;
    },

    //10进制转化成16进制
    Converto16: function (x) {

        return "0x" + parseInt(x).toString(16);
    },
    //显示老师不在的画面
    appendLeavePart:function () {

        $("#video_tip").show();

        var onCount = common.onlineCount;
        common.teacherIds = 0;

        var exitStr = "<header class='exit_page' id='exitPage'>" +
            "<div class='online-box'><span id='onlineSpan' class='onlineSpan'>" + onCount + "</span>人在线</div>" +
            "<div class='cinfo'>" +
            "<img src='"+common.imgUrl+"teach_leave.png' class='leave_img'>" +

            "</div>" +
            "</header>";

        $("#liHeader").html(exitStr);
    },

    //显示老师离开的页面
    showLeavePage: function () {

        //如果是金山项目，离课程结束3分钟内老师离开，弹出注册提示框

        if(common.qudaoNum == 10001){

            var endClassTime = $("#endTimeHid").val();

            //var timeCha = Number(endClassTime - common.teaLeaveTime);  //时间差的秒数
            console.log("课程结束时间:%s",endClassTime);
            console.log("当前时间:%s",common.teaLeaveTime);

            if(endClassTime > common.teaLeaveTime){
                var timeCha = Number(endClassTime - common.teaLeaveTime);  //时间差的秒数
                console.log("离下课还差秒:%s",timeCha);
                //计算相差分钟数
                if (timeCha <= 180) {

                    console.log("timeCha:%s",timeCha);

                    $("#tiyanBox").show();
                    $("#tiyanMask").hide();

                    $("#cloBtn").click(function () {
                        $("#tiyanBox").hide();
                        $("#tiyanMask").hide();
                    })

                    common.appendLeavePart();

                    return;
                }

            } else {

                console.log("老师上课时长超过课程结束时间");
                $("#tiyanBox").show();
                $("#tiyanMask").hide();

                $("#cloBtn").click(function () {
                    $("#tiyanBox").hide();
                    $("#tiyanMask").hide();
                })

                common.appendLeavePart();

                return;
            }


        }
        //音频模式下
        if(common.playKind == 1){

            $("#teaNoEnter").show()
                              .siblings("span").hide();

            return;

        }

        common.appendLeavePart();
    },

    //如果是2G、3G网络类型，显示提示页面
    show3GPage: function () {

        $("#video_tip").show();

        var onCount = common.onlineCount;

        var netType = common.warnInfo.netWorkType;

        var ua = common.getAppVersion();

        if (!(/MicroMessenger/.test(ua))) {

            netType = common.warnInfo.noKnowNetType;
        }

        var exitStr = "<header class='exit_page' id='Page3G'>" +
            "<div class='online-box'><span id='onlineSpan' class='onlineSpan'>" + onCount + "</span>人在线</div>" +
            "<div class='cinfo'>" +
            "<h2>"+netType+"</h2>" +
            "<img src='"+common.imgUrl+"play_icon.png' class='play_img' onclick='common.showVideoTip()'>" +
            "<a href='javascript:;' class='goAu_link'>只听声音（省流量）</a>" +
            "</div>" +
            "</header>";


        $("#liHeader").html(exitStr);

        //点击听声音链接
        $(".goAu_link").click(function () {

            common.playKind = 2;
            common.showVideoTip();
        })

    },

    //改变在线人数
    chgOnlineNum: function (num) {

        common.onlineCount = common.onlineCount + num;

        $(".onlineSpan").html(common.onlineCount);

    },
    //监听教室最大容量限制
    listenTeaCapacity:function(curVal){

        if(curVal == common.teaCapacity){
            common.teaCapacityFun(1);
            common.peakNotice = true;
        }
        if(curVal < common.teaCapacity && common.peakNotice){
            common.teaCapacityFun(0);
            common.peakNotice = false;
        }

    },
    // 教室最大容量限制
    teaCapacityFun: function (num) {

        var peak_type = 0;

        if (num > 0)
            peak_type = 1

        //当教室人数超过最大容量时，给服务端发送信息
        var submitUrl = "http://wxapi.51talk.com/Thirdparty/WeixinUser/peakNotice";
        $.ajax({
            url: submitUrl,
            type: "POST",
            data: {
                course_id: common.userAllInfo.res.meetInfo.appointId,
                channel: common.qudaoNum,
                peak_type: peak_type,
                extend: ""
            },
            success: function (info) {

                var result = info;

                if (result == "ok") {

                } else {

                    return ""
                }

            }
        })

    },
    //禁言提示
    banMessage: function (data) {

        //全员禁言
        if (data.classRight == "ban") {

            common.classBan = true;
            common.userBanId = 0;

            if ($("#userChatBox").find(".chat_item").length < 1){

                $("#userChatBox").html("");

                $("#wrapper").css("height",$("#slider").height()+"px");

                //显示静音模式下的图片

                var H = $("#wrapper").height() - $(".chat-box-back").height();

                var err = "<div class='mute_box' style='height:"+H+"px'>"+
                    "<div class='wen1'>"+common.warnInfo.mute+"</div>" +
                    "<div class='mid'><img src='"+common.imgUrl+"jiqiren.png' width='125' height='131'></div>"
                "</div>"

                $("#userChatBox").append(err);
                //-------------------------------------------------
                $(".chat_write_box").hide()
                                      .removeClass("dis-flex");
                return;

            } else {
                $("#wrapper").css("height",$("#slider").height()+"px");
            }

            //如果已经有聊天记录了，则在最底部显示静音提示
            if (!$("#userChatBox").find(".err_item").length) {

                $("#wrapper").css("height",$("#slider").height() - $(".chat-box-back").height() +"px");

                var err = "<div class='chat_item err_item'>" +
                    "<span class='errIcon'></span>"+(common.warnInfo.mute).replace("<br/>","")+"</div>";

                $(".chat-container").append(err);
                //滚动条总是在最底部
                common.chatScrollTop();

            }

            $(".chat_write_box").hide()
                                  .removeClass("dis-flex");
            return;
        }

        if (data.userRight == "ban") {

            common.userBanId = common.Converto10(data.userId);
            common.classBan = false;
            common.userBan = true;

            if ($("#userChatBox").children(".err_item").length) {

                $(".err_item").remove();
                $(".mute_box").remove();
                $(".chat_write_box").addClass("dis-flex");

                $("#wrapper").height($("#slider").height() - $(".chat-box-back").height() + "px");

            }

            return;
        }

        //解禁
        //全员
        if (data.userRight == "unban" && data.classRight == "unban") {

            common.classBan = false;
            common.userBan = false;
            common.userBanId = 0;

            $(".err_item").remove();
            $(".mute_box").remove();

            $(".chat_write_box").addClass("dis-flex");

            $("#wrapper").height($("#slider").height() - $(".chat-box-back").height() + "px");
            console.log("取消禁言情况下聊天区域高度:%s",$("#wrapper").height());

            return;

        }

    },

    //格式化时间（转化成12:20格式）
    formatDate: function (seconds) {

        var milliseconds = seconds * 1000;//秒变微秒
        var dat = new Date(milliseconds);//生成日期
        var year = dat.getFullYear();//取得年
        var month = dat.getMonth() + 1;    //取得月,js从0开始取,所以+1
        var date1 = dat.getDate(); //取得天
        var hour = dat.getHours();//取得小时

        if (hour < 10) hour = "0" + hour;

        var minutes = dat.getMinutes();//取得分钟

        if (minutes < 10) minutes = "0" + minutes;

        var second = dat.getSeconds();//取得秒

        return hour + ":" + minutes;
    },

    //插入视频播放状态到页面中(当正常播放时，显示提示及视频；当网络异常时，显示提示及错误视频)
    showVideoTip: function () {

        if (!common.classPlaying) return;

        //开课后，课前部分要隐藏
        $(".exit_page").hide();
        $("#btnplay").remove();

        if ($(".video_tip")) {

            $(".video_tip").remove();
        }

        if ($(".video_box")) {

            //如果音视频有监听事件，则移除
            common.audioVideoRemoveEvent();

            $(".video_box").remove();
        }

        var $top = $("<div class='video_tip clearfix'></div>");
        var $box = $("<div class='video_box' id='videoContainer'></div>");

        var onCount = common.onlineCount;

        if (common.conNormal) {

            if(common.isopenVedio == 1) {   //有视频情况下

                if(common.qudaoNum == 10001) {
                    var temp = "<span>正在直播...(<span id='onlineSpan' class='onlineSpan'>" + onCount + "</span>人在线)</span>";
                } else {
                    var temp = "<span>正在直播...(<span id='onlineSpan' class='onlineSpan'>" + onCount + "</span>人在线)</span>" + "<a onclick='common.chgPlayWay(this)' id='videoIco'><span  class='video_ico y_video'></span><span class='moshi'>视频模式</span></a>";
                }
            }
            //获取视频或者音频的播放器字符串
            var vdeUrl = common.videoOraudeio();

        }

        if (!common.conNormal) {

            var temp = "<span><span class='errIcon'></span>断网了，请检查网络设置。</span>" +
                "<span class='video_ico y_video' id='videoIco'></span>";

            var vdeUrl = "<div class='flex'>" +
                "<div class='video_down' id='videoDown'>" +
                "<img src='"+common.imgUrl+"banner_gray.png' class='banner_gray'>" +
                "<h1>视频连接失败</h1>" +
                "<a href='javascript:;' class='ref' id='vdRefBtn'>刷新一下</a>" +
                "</div>" +
                "</div>";

            //当视频连接失败时，刷新按钮点击事件
            common.eventGetVideoUrl();

        }

        $top.append(temp);
        $box.append(vdeUrl);

        $top.append($box);

        $("#liHeader").append($top)
                        .append($box);

        //对于IOS手机，视频切换到音频，播放器隐藏，生成一个播放按钮，用户点击按钮才会播放
        common.addPlayBtn(2);

        if (common.conNormal)
            common.videoUrl()
    },

    //针对IOS手机，对于所有音频模式下都增加播放按钮
    addPlayBtn:function (kind) {

        var phoneType = common.deviceType();
        if (phoneType == "iphone" && common.playKind == kind) {

            //截取版本号
            var appVerStr = common.getAppVersion();
            var osP = appVerStr.indexOf("OS") + 2;
            var lineP = appVerStr.indexOf("_");
            var verNum = parseInt(appVerStr.substring(osP,lineP));
            //IOS手机，纯音频模式下，如果系统版本小于9，添加上播放按钮
            //IOS手机，从视频切换到音频下，添加上播放按钮
            var btnPlayStr = "";
            if(common.playKind == 1){
                btnPlayStr = "<img src='"+common.imgUrl+"play_small.png' id='btnplay'>";
            }
            if(common.playKind == 2) {
                btnPlayStr = "<img src='"+common.imgUrl+"play_small.png' id='btnplay'>";
            }

            $("#liHeader").append(btnPlayStr);

            $("#btnplay").click(function () {

                document.getElementById("audioBox").play();
                //$("#liHeader").append(imgJumpStr);

                $(this).remove();
            })
        }

        //金山的安卓版本，去掉control
        if (common.playKind == 0 && common.qudaoNum == 10001 && common.getAppVersion().indexOf("CPU iPhone OS") < 0){
            document.getElementById("videoBox").controls = false;
        }
    },
    //音频或者视频的字符串
    videoOraudeio: function () {

        if (common.playKind == 0) {

            //5S手机下的特殊处理方式（把视频变小，在上面放张播放的图片）
            if(common.getAppVersion().indexOf("CPU iPhone OS 7") > 0){

                var imgVideo = "<img src='"+common.imgUrl+"play.png' class='iphone5-play-ico' id='play5s'>"
                var imgVideo = "";
                var videostr = imgVideo + "<video id='videoBox' class='videoRecord iphone5-play-ico' autoplay preload='auto' controls webkit-playsinline playsinline></video>";

                return videostr;

            } else {
                //金山渠道(金山APP中浏览器内核为webkit，播放器难看，所以上面放一层图片)
                //金山去掉  controls
                if(common.qudaoNum == 10001){

                    //IOS手机带control，安卓不带control
                    if(common.getAppVersion().indexOf("CPU iPhone OS") > 0){
                        return "<video id='videoBox' class='videoRecord' poster='"+common.imgUrl+"bg-img.png' autoplay preload='auto' controls webkit-playsinline playsinline></video>";
                    } else {
                        return "<video id='videoBox' class='videoRecord' poster='"+common.imgUrl+"bg-img.png' autoplay preload='auto' webkit-playsinline playsinline></video>";
                    }

                } else {
                    return "<video id='videoBox' class='videoRecord' autoplay preload='auto' controls webkit-playsinline playsinline></video>";
                }
            }
        } else {

            var audioMask = "";

            return common.showMp3Note()  + "<audio id='audioBox' class='videoRecord' autoplay preload='auto' controls></audio>";
        }
    },

    //检测系统版本号
    AppNum9:function(){

        var appVesionArr = [];

        var num9 = 0;

        for(var i=9;i<15;i++){

            appVesionArr.push("CPU iPhone OS "+i);
        }

        for(var i=0;i<appVesionArr.length;i++){

            if(common.getAppVersion().indexOf(appVesionArr[i]) > 0){

                num9 = 9;
                break;
            }
        }

        return num9;

    },
    //音视频切换
    chgPlayWay: function ($control) {

        //如果为金山的，则不切换音视频
        if(common.qudaoNum == 10001){
            return;
        }
        //切换到音频
        var $yin = $($control).find("span").eq(0);

        if ($yin.hasClass("y_video")) {

            common.playKind = 2;
            $yin.removeClass("y_video")
                .addClass("n_video");
            common.tipShow(common.warnInfo.endVdeio);


        } else {
            //切换到视频

            common.playKind = 0;
            $yin.removeClass("n_video")
                .addClass("y_video");
            common.tipShow(common.warnInfo.startVdeio);

        }

        common.showVideoTip();
    },
    //刷新按钮点击事件
    eventGetVideoUrl: function () {

        $("#beforeContainer").on("click", "#vdRefBtn", function () {

            common.videoUrl();
        })
    },

    //请求视频地址(参数表示播放器的ID)
    videoUrl: function () {

        //openid 表示老师ID，cid 表示课程ID
        var openid = common.userAllInfo.res.meetInfo.teaId;
        var cid = common.userAllInfo.res.meetInfo.appointId;

        var submitUrl = "http://60.205.90.168/api/getlink?cid=" + cid + "&openid=T_" + openid + "&classType=1&ex_audio=" + common.playKind;

        var videoName = "videoBox";

        if (common.playKind == 1 || common.playKind == 2) {

            videoName = "audioBox";

            $("#videoIco").find("span").eq(0).removeClass("y_video");
            $("#videoIco").find("span").eq(0).addClass("n_video");
            $(".moshi").html("音频模式");

        } else {

            videoName = "videoBox";
        }

        $("#videoBox").remove();

        if(common.playKind == 2){

            $("#audioBox").remove()
        }

        $(".demo-music").remove();

        if (common.playKind == 0 || common.playKind == 2) {
            $(".video_box").append(common.videoOraudeio());
        }

        //增加播放按钮
        common.addPlayBtn(1);

        console.log("请求音视频地址");
        common.requestVideoUrl(videoName, submitUrl);

    },
    //请求音视频地址
    requestVideoUrl: function(videoName, submitUrl){

        //只重试1次
        if(common.timoutCount >1 || common.errorCount > 1) return;

        console.log("common.timoutCount:%s",common.timoutCount);
        console.log("common.errorCount:%s",common.errorCount);
        $.ajax({
            url: submitUrl,
            type: "GET",
            timeout: common.timeoutStr,
            success: function (info) {

                var result = info.result;

                if (result.code == 200) {

                    console.log("yy地址:%s",result.data.url);
                    var okPlay = false;
                    common.timoutCount = 0;
                    common.errorCount = 0;

                    $("#" + videoName).attr("src", result.data.url);

                    if (/MicroMessenger/.test(common.getAppVersion())) {

                        if (common.playKind == 1){

                            common.audioIsCanPlay();
                            return;
                        }
                    } else {

                        $("#zhiboing .clock").show();
                    }

                    window.setTimeout(function(){

                        //自动播放音视频
                        document.addEventListener("WeixinJSBridgeReady", function (e) {

                            document.getElementById(videoName).play();

                            $("#zhiboing .clock").show();

                            okPlay = true;

                        }, false);

                        //给视频区域固定宽度和高度
                        $(".video_box").height($("#liHeader").height()-$(".video_tip").height()+"px");
                        $(".video_box").width($(window).width()+"px");

                        if(common.playKind == 2){
                            common.audioPaused();
                        }

                        //监听音频暂停和播放状态
                        //common.audioPaused();
                        common.videoPlayStatus(videoName, submitUrl);

                    },300)

                } else {    //返回错误码时

                    console.log("result.code:%s",result.code);
                    common.errorCount++;
                    //if(common.errorCount <= 1)
                        //common.requestVideoUrl(videoName, submitUrl);
                }

            },
            //超时设置
            error:function(XMLHttpRequest,status){

                if(status == 'timeout'){//超时,status还有success,error等值的情况

                    common.timoutCount++;

                    // if(common.timoutCount <= 1)
                    //     common.requestVideoUrl(videoName, submitUrl);
                }
            }
        })
    },
    //移除音视频所有的监听事件
    audioVideoRemoveEvent:function(){

        var audioBox = document.getElementById("audioBox");

        if(audioBox){

            audioBox.removeEventListener("pause", common.AudioPauseEvent);

            audioBox.removeEventListener("play", common.AudioPlayEvent);
        }

        var videoBox = document.getElementById("videoBox");

        if(videoBox){

            //videoBox.removeEventListener("pause", common.videoPauseEvent);

            videoBox.removeEventListener("canplaythrough", common.videoPlayEvent);
        }

    },
    AudioPauseEvent:function(){
        $("#audioImgs").attr("src", common.imgUrl+"jump.png");
    },
    AudioPlayEvent:function(){
        $("#audioImgs").attr("src", common.imgUrl+"jump.gif");
    },
    videoPlayEvent:function(){

        var videoBox = document.getElementById("videoBox");

        videoBox.play();
    },
    //监听音频暂停和播放状态
    audioIsCanPlay:function(){

        var audioBox = document.getElementById("audioBox");

        if(audioBox){

            audioBox.addEventListener("timeupdate", function () {
                common.audioInfo.curTime = audioBox.currentTime;
            });

            audioBox.addEventListener('canplaythrough', function () {

                audioBox.play();

                $("#zhiboing .clock").show();

                if(common.audioInfo.canNum <=1){
                    common.audioRepeatLoad();
                }

                common.audioInfo.canNum++;
            });

        }
    },
    audioRepeatLoad:function(){

        common.audioInfo.winTimeout = window.setTimeout(function(){

            if(common.audioInfo.curTime < 1){

                if(common.audioInfo.num < 3){

                    common.audioInfo.curTime = -1;

                    common.audioInfo.num++;

                    common.audioInfo.timePoint = common.audioInfo.timePoint + 2000;

                    document.getElementById("audioBox").load();

                    common.audioRepeatLoad();

                } else {

                    window.clearTimeout(common.audioInfo.winTimeout);

                    var str = "<div class='noAudioInfo' id='noAudioInfo'><span>听不到声音？请升级微信版本</span></div>"
                    $("body").append(str);

                    window.setTimeout(function(){

                        $("#noAudioInfo").remove();

                    },5000)

                }

            }

        },common.audioInfo.timePoint)

    },
    audioPaused:function(){

        var audioBox = document.getElementById("audioBox");

        if(audioBox){

            audioBox.addEventListener("pause", common.AudioPauseEvent);

            audioBox.addEventListener("play", common.AudioPlayEvent);

            audioBox.addEventListener("canplay",function(e){

                $("#audioImgs").attr("src", common.imgUrl+"jump.gif");

            });

            audioBox.addEventListener("error",function(e){

                $("#audioImgs").attr("src", common.imgUrl+"jump.png");

            });

        }
    },
    //监听视频暂停和播放状态
    videoPlayStatus:function(videoName, submitUrl){

        var videoBox = document.getElementById("videoBox");

        if(videoBox){

            videoBox.addEventListener("error",function(e){

                //1.用户终止 2.网络错误 3.解码错误 4.媒体资源不可用或媒体格式不被支持
                console.log("错误代码：%s",e.target.error.code);
                console.log(common.videoErrArr[e.target.error.code]);

                //alert(common.videoErrArr[e.target.error.code]);
                //common.requestVideoUrl(videoName, submitUrl);

            });

             videoBox.addEventListener('canplaythrough', common.videoPlayEvent)

        }
    },
    //当音频时，显示音符跳动
    showMp3Note: function () {

        var mp3Str = "<div class='demo-music'></div>";
        return mp3Str;

    },
    //用户被踢提醒
    userKicked: function (data) {

        common.tipShow(common.warnInfo.kicked);

        //窗口关闭，在线人数减1
        window.setTimeout(function () {

            if(common.isWeixin()){

                //微信直播则直接关闭，金山项目则跳转到被踢提示页面
                //微信直播渠道号10000,金山10001
                if(common.qudaoNum == 10000){

                    WeixinJSBridge.call('closeWindow');
                } else {

                    window.location.href = "/Ac/AcService/kick";
                }

            } else {
                window.history.back();
            }

        }, 2000)
    },

    //聊天滚动到最下面
    chatScrollTop: function(){

        window.setTimeout(function(){

            var $box = $(".chat_box").find("div");

            $box.scrollTop($box[0].scrollHeight);

            var H = $box[0].scrollHeight;

        },100)
    },
    //监听网络状态
    listerNetStatus: function(){

        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', common.onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', common.onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', common.onBridgeReady);
            }
        }else{

            common.onBridgeReady();
        }

    },
    onBridgeReady: function(){

        WeixinJSBridge.invoke('getNetworkType',{},
            function(e){

                var network = e.err_msg.split(":")[1];

                if (network != "wifi") {
                    return false;
                } else {
                    return true;
                }

            });
    },
    //判断用户类型//老师：1，学生：2，自己：21，助教：3
    customerType: function (data) {

        var userId = common.Converto10(data.userId);

        if (userId == common.userId)

            return "21"

        else if (userId == common.teacherIds)

            return "1"

        else if (userId == common.helperId)

            return "3"
        else

            return "2";

    },

    //判断网络类型（wifi\2G\3G）
    isWifiFun: function () {

        var wifi = false;
        var ua = common.getAppVersion();
        var con =window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection || null

        // 如果是微信
        if (/MicroMessenger/.test(ua)) {
            // 如果是微信6.0以上版本，用UA来判断
            if (/NetType/.test(ua)) {

                if (ua.indexOf('WIFI') != -1) {
                    wifi = true;
                } else {
                    wifi = false;
                }
                // 如果是微信6.0以下版本，调用微信私有接口WeixinJSBridge
            } else {

                document.addEventListener("WeixinJSBridgeReady", function() {

                    WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
                        if(e.err_msg.indexOf(":") > 0)
                            var network = e.err_msg.split(":")[1];
                        else
                            var network = e.err_msg;

                        if (network != "wifi") {
                            wifi = false;
                        }
                    });
                },false);
            }
            // 如果支持navigator.connection
        } else if (con) {
            if(con!=null){
                var network = con.type;
                if (network != "wifi" && network != "2" && network != "unknown") {  // unknown是为了兼容Chrome Canary
                    wifi = false;
                }
            }else{
                //alert('无法获取您的数据连接类型');
            }

        }

        return wifi;

    },
    //过滤一些非法字符
    removeDanger: function(str){

        var newStr = str;

        newStr = newStr.replace(/&/g, "&amp;");
        newStr = newStr.replace(/\\/g, "&quot;");
        newStr = newStr.replace(/'/g, "&#039;");
        newStr = newStr.replace(/</g, "&lt;");
        newStr = newStr.replace(/>/g, "&gt;");

        return newStr;

    },
    //在PC端浏览器播放的视频
    pcPlayVdeio: function (videoname, url) {

        if (Hls.isSupported()) {

            var video = document.getElementById(videoname);
            var hls = new Hls();
            // hls.loadSource('http://www.streambox.fr/playlists/test_001/stream.m3u8');
            hls.attachMedia(video);

            hls.on(Hls.Events.MEDIA_ATTACHED, function () {

                hls.loadSource(url);
                hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
                    video.play();
                });
            });

        } else {
            document.getElementById(videoname).src = url;
        }
    }
}
define("comm_server",function (require, exports, module) {

    //根据测试环境设置socket连接地址
    var preUrl = "pre.51talk.com";
    var lineUrl = "www.51talk.com";

    //测试环境
    //var DEFAULT = 'ws://172.16.16.30:3000';

    //线上环境
    var DEFAULT = 'ws://60.205.91.131:80';

    var fixurl = window.location.host;

    if(fixurl == preUrl || fixurl == lineUrl){

        DEFAULT = 'ws://60.205.91.131:80';
    }

    console.log("svc地址：%s",DEFAULT);
    var userName='';

    window.comServer={

        init: function () {

            this.socket=null;
            this.socket = io.connect(DEFAULT, {"transports": ["websocket"]});
            this.socket.on('connect', function () {

                comServer.data('login','login');
            });

            this.socket.on('error', function (err) {

                common.IsCon = false;
                comServer.close();
            });

            this.socket.on('connect_failed', function (e) {
                common.IsCon = false;
                comServer.close();
            });
            this.socket.on('reconnecting', function (e) {
                if(e>3){

                    comServer.close();
                }else{

                }

            });

            this.socket.on('disconnect', function (err) {

                common.IsCon = false;
                comServer.close();
            });

            this.socket.on('clientRecvData', function (data) {

                RecvData(JSON.parse(data));

            });
        },

        data: function (type1,type2,str) {

            var obj=null;

            if(type1=='login'){

                var tem_e = common.userAllInfo;

                obj={
                    'type':'login',
                    'subType':'login',
                    'data':{
                        'userName':tem_e.res.roleInfo.roleName,
                        'role':tem_e.res.roleInfo.role,
                        'userId':common.Converto16(tem_e.res.roleInfo.roleId),
                        'classID':common.Converto16(tem_e.res.meetInfo.appointId),
                        'classType':""+tem_e.res.meetInfo.classType+"",
                        'deviceType':common.deviceType(),
                        'AVSDK':[1,2]
                    }
                };
            console.log("登录需要的对象参数：%o",obj);

            }else if(type1=='data'){
                switch (type2){
                    case 'chat':
                        if(str.length!=0){

                            obj={
                                'type':'data',
                                'subType':'chat',
                                'data':{
                                    'userId':common.Converto16(common.userId),
                                    'userName':common.userAllInfo.res.roleInfo.roleName,
                                    'opt':'ft=å®‹ä½“|cr=0|hi=10|bd=0|it=0|ul=0',    //??????
                                    'content':str,
                                    'sentTime':common.Converto16(parseInt((new Date().getTime()) / 1000))  //ç”¨æˆ·å½“å‰?å?‘é€?æ—¶é—´ï¼ˆå¿…é¡»è½¬åŒ–æˆ?1970å¹´ä»¥æ?¥çš„ç§’æ•°ï¼‰
                                }
                            };
                        }

                        break;
                    default :

                        console.log('undefined data type for server : %s',type2);
                        break;
                }
            }else{

                console.log('undefined type for server : %s',type1);
            }

            if(obj!=null){

                this.socket.emit('serverRecvData', JSON.stringify(obj));
            }
        },
        close: function () {
            try{
                // this.socket.close();
                // this.socket.destroy();
            }catch(e){
                console.log('error happened when release server connection : %s'+e);
            }
            var obj= {
                'type': 'error',
                'subType': 'svcError',
                'data': {
                    'reason':'error'
                }
            }
        }
    }

    var RecvData= function (e) {

        var obj=null;

        if(e.type=='login'){

            if(e.subType=='loginAck'){

                obj = e;

                common.teacherId = obj.data.teacherIds;

            }else{

                console.log('undefined login type from server : (subType : %s)',e.subType);
            }
        }

        obj = e;

        if(obj){
            comm_sendClient(obj);
        }
    }

    function comm_sendClient(obj) {

        window.handleShakedataServer(obj);
    }

    function callback(t){

    }

    exports.comm_login= function() {

        comServer.init();

    };

    exports.comm_relogin= function() {

        comServer.init();

    };

    exports.comm_data= function (type1,type2,str) {

        comServer.data(type1,type2,str);
    }
});
define("chat",['comm_server'],function(require,exports,module){

    var commServer = require('comm_server');

    var chat_text=$('#chatTxt');
    var send_btn=$('#chatSend');
    var hide_chat_btn = $('#hideChatBtn');

    var text_init='';
    var oldTime = '';
    var arr_div=[];
    var imgArr = [];
    var _copy=true,
        _select=false,
        _save=true,
        _clear=true,
        _send=false;

    exports.tra_on_off=true;

    exports.eventBind= function () {

        //发送信息
        send_btn.click(function (e) {

            send();
            e.stopPropagation();

        });

        hide_chat_btn.click(function (e) {

            var $this = $(this);

            if($this.hasClass("teach_btn")){

                hideChatItem("teach_btn");

                common.teacherMode = false;

            } else {

                hideChatItem("student_btn");

                common.teacherMode = true;

            }

            e.stopPropagation();
        });

    }

    //点击头像后，隐藏学生内容，只显示老师聊天内容
    function hideChatItem(str){

        if(str == "teach_btn"){

            hide_chat_btn.addClass("student_btn")
                        .removeClass("teach_btn");
            hide_chat_btn.html("所有人");

            $("#userChatBox").children().show();

        } else {

            hide_chat_btn.addClass("teach_btn")
                        .removeClass("student_btn");
            hide_chat_btn.html("老 师");
            $("#userChatBox").children(":not(.teach_item)").hide();

            common.tipShow(common.warnInfo.onlyTeachTip);
        }

        //滚动条总是在最底部

        common.chatScrollTop();

    }

    //转换表情
    function utf16toEntities(str) {
        var patt=/[\ud800-\udbff][\udc00-\udfff]/g;
        // 检测utf16字符正则
        str = str.replace(patt, function(char){
            var H, L, code;
            if (char.length===2) {
                H = char.charCodeAt(0);
                // 取出高位
                L = char.charCodeAt(1);
                // 取出低位
                code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00;
                // 转换算法
                return "&#" + code + ";";
            } else {
                return char;
            }
        });
        return str;
    }
    function entitiestoUtf16(str){
        // 检测出形如&#12345;形式的字符串
        var strObj=utf16toEntities(str);
        var patt = /&#\d+;/g;
        var H,L,code;
        var arr = strObj.match(patt)||[];
        for (var i=0;i<arr.length;i++){
            code = arr[i];
            code=code.replace('&#','').replace(';','');
            // 高位
            H = Math.floor((code-0x10000) / 0x400)+0xD800;
            // 低位
            L = (code - 0x10000) % 0x400 + 0xDC00;
            code = "&#"+code+";";
            var s = String.fromCharCode(H,L);
            strObj.replace(code,s);
        }
        return strObj;
    }
    function send(){

        //为空不能发送
        var chatTxt = $.trim(chat_text.val());

        if(chatTxt == ''){

            return;

        }

        //过滤javascrit字符串

        chatTxt = common.removeDanger(chatTxt);

        //判断是否被禁言
        //全员
        if(common.classBan){

            common.tipShow(common.warnInfo.allBan);
            return;
        }
        //单个学生
        if(common.userBan){

            if(common.userBanId == common.userId){

                common.tipShow(common.warnInfo.oneBan);
                return;
            }

        }

        if(chatTxt.length > 200){

            common.tipShow(common.warnInfo.moreLen);
            return;
        }

        //检查是否登录成功
        if(!common.IsCon){

            common.tipShow(common.warnInfo.netWork);
            commServer.comm_relogin();
            return;
        }

        var obj={

            'type':'data',
            'subType':'chat',
            'data':{
                'userId':common.Converto16(common.userId),
                'userName':common.userAllInfo.res.roleInfo.roleName,
                'opt':'ft=宋体|cr=0|hi=10|bd=0|it=0|ul=0',    //??????
                'content':chatTxt,
                'sentTime':common.Converto16(parseInt((new Date().getTime()) / 1000))  //用户当前发送时间（必须转化成1970年以来的秒数）
            }
        };
        console.log("聊天发送的对象:%o",obj);

        //发送成功后时间间隔必须大于5S
        if(!oldTime){

            oldTime = new Date();

        } else {

            var curTime = new Date();

            if((curTime.getTime() - oldTime.getTime())/1000 < common.limitSpeakTime) {

                common.tipShow(common.warnInfo.fastTime);
                return;
            }

            oldTime = curTime;
        }


        //参数1表示输入内容；参数2表示发言人身份（其它学生、自己、老师、助教）
        //自己发的信息，在聊天区域直接显示出来(服务端不返回自己发的信息)
        record_chat.add(obj.data, "21");

        //向服务端发送数据
        commServer.comm_data('data','chat',chatTxt);
        chat_text.val('');

    }

    //讨论区域，如果老师发言了，同时也以通知方式显示老师的谈话内容
    //username:名称；content:发言内容；userType：老师还是助教
    var showNoticeMessage = function(userName, content, userType) {

        var $list = $("#contain_chat");

        var $msgBox = $("<div class='tea_message' id='teaMessage'></div>");

        var userTypeArr = ["","[老师] ","","[助教] "];

        var tempInfo = $("<span class='marquee'>" + userTypeArr[parseInt(userType)] + userName + "："  + content + "</span>");

        var x = $list.width();

        tempInfo.css({"left":x+"px"});

        //如果已经有tea_message，则直接添加内容
        if (!$list.find(".tea_message").length) {

            $msgBox.append(tempInfo);
            $list.append($msgBox);

        } else {

            tempInfo.css({"left":(x+100)+"px"});
            $list.find(".tea_message").append(tempInfo);
        }

        //当老师提示框中没有内容移动时，提示框消失

        var _rect = document.getElementById('teaMessage');

        _rect.style.display = "block";

        var chid = _rect.children;

        for(var i=0;i<chid.length;i++){

            chid[i].addEventListener('webkitAnimationEnd', addAnimatEvent, false);

        }

        //////////////////////////////////////////////////

    }

    var addAnimatEvent = function(){

        var _rect = document.getElementById('teaMessage');

        $(this).remove();
        var tchild = _rect.children;
        if(!tchild.length)
            _rect.style.display = "none";

        this.removeEventListener('webkitAnimationEnd', addAnimatEvent, false)
    }

    //显示聊天内容
    var record_chat=(function () {

        var index= 0,num = 0;
        var maxCount=300;//最大300

        var add_record=function(data,type){

            var div_child_text = $("#userChatBox");

            var chatH = parseInt($("#userChatBox").height());

            var dl_parent,
                dl_dt,
                dl_dd,
                dl_child_text,
                dl_child_img;

            var urlArr = [];

            if(data){

                var userName = data.userName;
                var content = data.content;
                var imgsrc = content;
                //返回的是秒数，需要转成时间格式：12:30
                var sentTime = common.formatDate(common.Converto10(data.sentTime));

            }

            dl_parent=$('<dl></dl>');
            dl_dt=$('<dt></dt>');
            dl_dd=$('<dd></dd>');

            //在只显示老师模式下，其它学生发过来的信息也要隐藏

            if(common.teacherMode){

                if(type != 1)
                    dl_parent.attr('style','display:none');
            }

            dl_parent.attr('class','chat_item');
            dl_dt.attr('class','clearfix');
            dl_dd.attr('class','chat_nr');

            //老师：1，学生：2，自己：21，助教：3

            switch (type){

                case "1":

                    dl_parent.addClass("teach_item");
                    dl_dt.append("<em class='bt emT'>老师</em><span>"+sentTime+"</span>");

                    //当老师发送图片时

                    if(data.status == "inprogress"){

                        if(content.indexOf("[Image:{") >= 0) {

                            var reg = /\[Image:\{[^\}]*/gi;

                            var strArr = content.match(reg);

                            for(var i=0;i<strArr.length;i++){

                                var url = strArr[i]+"}]";
                                var imgsrc = strArr[i].replace("[Image:{", "");
                                var loading = "<img src='../../images/loading.gif' lazy-src='"+imgsrc+"' style='width:55px;height:auto' data-num='"+(index++)+"'>";

                                content = content.replace(url, loading);

                            }

                        } else {
                            //当前处于讨论区哉时，显示浮动条
                            if(common.playKind == 0 || common.playKind == 2) {

                                if ($("#pagenavi li").eq(1).find("span.active").length > 0)
                                    showNoticeMessage(userName, content, type);
                            } else {
                                if ($("#pagenavi li").eq(0).find("span.active").length > 0)
                                    showNoticeMessage(userName, content, type);
                            }
                        }

                    }

                    if(data.status == "complete"){

                        var reg = /\[Image:\{[^\}]*/gi;

                        var strArr = (content.match(reg))[0];
                        var imgsrc = strArr.replace("[Image:{", "");

                        loadPicUrl(imgsrc,num++);

                        return;
                    }
                    //如果显示静音模式图片，则删除
                    $(".mute_box").remove();
                    
                    break;

                case "2":

                    dl_dt.append("<em class='bt usr'>"+userName+"</em><span>"+sentTime+"</span>");

                    if(data.status == "inprogress"){

                        if(content.indexOf("[Image:{") >= 0) {

                            var reg = /\[Image:\{[^\}]*/gi;

                            var strArr = content.match(reg);

                            for(var i=0;i<strArr.length;i++){

                                var url = strArr[i]+"}]";
                                var imgsrc = strArr[i].replace("[Image:{", "");
                                var loading = "<img src='../../images/loading.gif' lazy-src='"+imgsrc+"' style='width:55px;height:auto' data-num='"+(index++)+"'>";

                                content = content.replace(url, loading);

                            }

                        }

                    }

                    if(data.status == "complete"){

                        var reg = /\[Image:\{[^\}]*/gi;

                        var strArr = (content.match(reg))[0];
                        var imgsrc = strArr.replace("[Image:{", "");

                        loadPicUrl(imgsrc,num++);

                        return;

                    }

                    break;

                case "21":

                    dl_parent.addClass("me_item");
                    dl_dt.append("<span>"+sentTime+"</span><em class='bt usr'>我</em>");
                    break;
                case "3":

                    dl_parent.addClass("teach_item");
                    dl_dt.append("<em class='bt emZ'>助教</em><span>"+sentTime+"</span>");

                    if(data.status == "inprogress"){

                        if(content.indexOf("[Image:{") >= 0) {

                            var reg = /\[Image:\{[^\}]*/gi;

                            var strArr = content.match(reg);

                            for(var i=0;i<strArr.length;i++){

                                var url = strArr[i]+"}]";
                                var imgsrc = strArr[i].replace("[Image:{", "");
                                var loading = "<img src='../../images/loading.gif' lazy-src='"+imgsrc+"' style='width:55px;height:auto' data-num='"+(index++)+"'>";

                                content = content.replace(url, loading);

                            }

                        } else {

                            //当前处于讨论区哉时，显示浮动条
                            if(common.playKind == 0 || common.playKind == 2) {

                                if ($("#pagenavi li").eq(1).find("span.active").length > 0)
                                    showNoticeMessage(userName, content, type);
                            } else {
                                if ($("#pagenavi li").eq(0).find("span.active").length > 0)
                                    showNoticeMessage(userName, content, type);
                            }

                        }

                    }

                    if(data.status == "complete"){

                        var reg = /\[Image:\{[^\}]*/gi;

                        var strArr = (content.match(reg))[0];
                        var imgsrc = strArr.replace("[Image:{", "");

                        loadPicUrl(imgsrc,num++);

                        return;

                    }

                    break;
            }

            dl_dd.append("<span>"+content+"</span>");
            dl_parent.append(dl_dt);
            dl_parent.append(dl_dd);

            div_child_text.append(dl_parent);

            index++;

            //如果聊天记录大于500条，则删除最旧的一条，释放内存
            if(index > maxCount){

                var dl0 = div_child_text.children("dl").eq(0);
                dl0.remove();
                dl0 = null;
                delete dl0;
                //if(CollectGarbage)CollectGarbage();
                index--;
            }

            //滚动条总是在最底部
            common.chatScrollTop();

            //当自己发送成功后，发送按钮变为灰色
            if(type == "21"){

                $("#chatSend img").attr("src", common.imgUrl+"send_grey.png");

            }

        };

        return {
            init:function(src){
                //init_data(src);
            },
            add: function (data,type) {

                add_record(data,type);

            },

        }
    })();

    //加载图片
    function loadPicUrl(src,index){

        (function(i){

            imgArr[i] = new Image();
            imgArr[i].onload = function(){

                var $tempImg = $(".chat_nr img[lazy-src='"+src+"']");

                if(imgArr[i].width >= $(".chat_nr").width()){

                    $tempImg.css({width:"100%",height:"auto"})
                } else{
                    $tempImg.css({width:"auto",height:"auto"})
                }


                $tempImg.attr("src", src);

            }
            imgArr[i].src = src;

        })(index)

    }
    //聊天对话中，发言
    exports.chatInfo_add = function(data, type){

        record_chat.add(data, type);
    }

});
define("paintWeb",['zTouch'],function (require, exports, module) {
    var constants={//静态常量
        COLORTEA:'#FF0000',
        COLORSTU:'#0078FF',
        COLORSTUSIGN:'#FFFF00',
        COLORTEASIGN:'#FF0000',
        COLORTARGET:'#0000FF',
        Arr_scroll:[],
        TEATYPE:[1,4,6,7],
        STUTYPE:['stu','cc']
    };
    var zTouch=require('zTouch');
    var WEBTools={
        svcId:1,//代表服务器所需id
        order_list:[],//存储所有操作顺序
        pDone_Arr:[],//存储所有笔迹
        timer:null,
        canvas:null,//document.getElementById("canvas");
        context:null,//canvas.getContext('2d');
        conf:{//配置信息
            versionType:'old',//版本
            page:{
                curpageNum:0,
                count:1
            },
            tea:{
                'pageNum':1,
                'login':false
            },
            pencil:{//画笔
                size:3,
                size_sign:20,
                color:constants.COLORSTU,
                color_sign:constants.COLORSTUSIGN,
                color_target:constants.COLORTARGET,
                rubbersize:30
            },
            font:{//文字
                fontstyle:'songti',
                fontSize:25,
                color:constants.COLORSTU
            },
            canvas:{
                width:1,
                height:1
            }
        },
        init: function () {

            this.svcId=1;
            this.order_list=[];
            this.pDone_Arr=[];
            this.canvas=document.getElementById("paint_canvas");
            this.conf.canvas.width=$('#paint_canvas').width();
            this.conf.canvas.height=$('#paint_canvas').height();
            this.context=this.canvas.getContext('2d');
        },
        reviewData: function () {
            if(WEBTools.canvas==null){
                WEBTools.init();
            }
            WEBTools.conf.canvas.width=$('#paint_canvas').width();
            WEBTools.conf.canvas.height=$('#paint_canvas').height();
            WEBTools.repaint();
        },
        data_mouse: function (obj) {
            var canvasW=parseInt(obj.canvasWidth,16),
                canvasH=parseInt(obj.canvasHeight,16),
                posLeft=parseInt(obj.xOffset,16),
                posTop=parseInt(obj.yOffset,16);
            var s=WEBTools.conf.canvas.width/canvasW;
            $('#mouseUpdate').animate({
                'left':parseInt(posLeft*s),
                'top':parseInt(posTop*s)
            },"fast");
        },
        data_pencil: function (obj) {
            var tem=WEBTools.toInt10(obj.rectangle);
            var canvasW=tem[1].x-tem[0].x,
                canvasH=tem[1].y-tem[0].y;
            var e={
                'handleType':0,
                'drawingType':0,
                'id':WEBTools.svcId,
                'specialValue':{
                    'pencil_color':'#'+obj.pencilColor.substr(2,6),
                    'pencil_size':WEBTools.toInt10(obj.pencilSize),
                    'canvasWidth':WEBTools.toInt10(obj.canvasWidth),
                    'canvasHeight':WEBTools.toInt10(obj.canvasHeight),
                    'child_div_W':canvasW,
                    'child_div_H':canvasH,
                    'margin_left':tem[0].x,
                    'margin_top':tem[0].y,
                    'point':WEBTools.toInt10(obj.linePoint)
                }
            };
            var target=new paint(e);
            target.init_paint(e);
            target.handle(WEBTools.context);
        },
        data_signPen: function (obj) {
            var e={
                'handleType':0,/*代表新的画笔*/
                'drawingType':10,/*荧光笔*/
                'id':WEBTools.svcId,
                'specialValue':{
                    'pencil_color':obj.specialValue.pencil_color,
                    'pencil_size':obj.specialValue.pencil_size,
                    'canvasWidth':obj.specialValue.canvasWidth,/*画布大小*/
                    'canvasHeight':obj.specialValue.canvasHeight,/*画布大小*/
                    'child_div_W':obj.specialValue.child_div_W,/*子画笔大小*/
                    'child_div_H':obj.specialValue.child_div_H,/*子画笔大小*/
                    'margin_left':obj.specialValue.margin_left,/*子画笔左上角距离画布左上角距离，即左上角的点坐标*/
                    'margin_top':obj.specialValue.margin_top,/*子画笔左上角距离画布左上角距离，即左上角的点坐标*/
                    'point':obj.specialValue.point
                }
            };
            var target=new paint(e);
            target.init_paint(e);
            target.handle(WEBTools.context);
        },
        data_rectangle: function (obj) {
            var tem=WEBTools.toInt10(obj.rectangle);
            var canvasW=tem[1].x-tem[0].x,
                canvasH=tem[1].y-tem[0].y;
            var e={
                'handleType':0,/*代表新的画笔*/
                'drawingType':2,/*矩形*/
                'id':WEBTools.svcId,
                'specialValue':{
                    'pencil_color':'#'+obj.pencilColor.substr(2,6),
                    'pencil_size':WEBTools.toInt10(obj.pencilSize),
                    'canvasWidth':WEBTools.toInt10(obj.canvasWidth),
                    'canvasHeight':WEBTools.toInt10(obj.canvasHeight),
                    'child_div_W':canvasW,
                    'child_div_H':canvasH,
                    'margin_left':tem[0].x,
                    'margin_top':tem[0].y,
                    'point':tem
                }
            };
            var target=new paint(e);
            target.init_paint(e);
            target.handle(WEBTools.context);
        },
        data_rubber: function (obj) {
            var tem=WEBTools.toInt10(obj.rectangle);
            var canvasW=tem[1].x-tem[0].x,
                canvasH=tem[1].y-tem[0].y;
            var e={
                'handleType':0,/*代表新的画笔*/
                'drawingType':3,
                'id':WEBTools.svcId,
                'specialValue':{
                    'pencil_color':'#'+obj.pencilColor.substr(2,6),
                    'pencil_size':WEBTools.toInt10(obj.pencilSize),
                    'canvasWidth':WEBTools.toInt10(obj.canvasWidth),
                    'canvasHeight':WEBTools.toInt10(obj.canvasHeight),
                    'child_div_W':canvasW,
                    'child_div_H':canvasH,
                    'margin_left':tem[0].x,
                    'margin_top':tem[0].y,
                    'point':WEBTools.toInt10(obj.linePoint)
                }
            };
            var target=new paint(e);
            target.init_paint(e);
            target.handle(WEBTools.context);
        },
        data_newRubber: function (obj) {
            var e={
                'handleType':0,
                'drawingType':500,
                'id':WEBTools.svcId,
                'specialValue':{
                    'id': obj.specialValue.id,
                    'type': 0
                }
            };
            var target=WEBTools.e_search(e.specialValue.id);
            if(target!=null){
                target.init_paint(e);
            }else{
                console.error('error happened when search target from local memory,handle type is : newRubber,target id is : %s',obj.id);
            }
            WEBTools.repaint();
        },
        data_text: function (obj) {
            var tem=WEBTools.toInt10(obj.rectangle);
            var canvasW=tem[1].x-tem[0].x,
                canvasH=tem[1].y-tem[0].y;
            var e={
                'handleType':0,
                'drawingType':4,
                'id':WEBTools.svcId,
                'specialValue':{
                    'font':{
                        'font_color':'#'+obj.pencilColor.substr(2,6),
                        'font_size':WEBTools.toInt10(obj.pencilSize),
                        'font_style':'songti'
                    },
                    'canvasWidth':WEBTools.toInt10(obj.canvasWidth),
                    'canvasHeight':WEBTools.toInt10(obj.canvasHeight),
                    'child_div_W':canvasW,
                    'child_div_H':canvasH,
                    'margin_left':tem[0].x,
                    'margin_top':tem[0].y,
                    'str_text':obj.text
                }
            };
            var target=new paint(e);
            target.init_paint(e);
            target.handle(WEBTools.context);
        },
        data_reEdit: function (obj) {
            var e={
                'handleType': 0,
                'drawingType':500,
                'id':WEBTools.svcId,
                'specialValue':{
                    'id':obj.specialValue.id,
                    'type':2,
                    'font':{
                        'font_color':obj.specialValue.font.font_color,
                        'font_size':obj.specialValue.font.font_size,
                        'font_style':obj.specialValue.font.font_style
                    },
                    'child_div_W': obj.specialValue.child_div_W,
                    'child_div_H': obj.specialValue.child_div_H,
                    'drag_left':obj.specialValue.drag_left,
                    'drag_top':obj.specialValue.drag_top,
                    'str_text':Base64.decode(obj.specialValue.str_text)
                }
            };
            var target=WEBTools.e_search(e.specialValue.id);
            if(target!=null){
                target.init_paint(e);
            }else{
                console.error('error happened when search target from local memory,handle type is : reEdit,target id is : %s',obj.id);
            }
            WEBTools.repaint();
        },
        data_drag: function (obj) {
            var e={
                'handleType': 0,
                'drawingType':500,
                'id':WEBTools.svcId,
                'specialValue':{
                    'id': obj.specialValue.id,
                    'type':1,
                    'drag_left': obj.specialValue.drag_left,
                    'drag_top': obj.specialValue.drag_top
                }
            };
            var target=WEBTools.e_search(e.specialValue.id);
            if(target!=null){
                target.init_paint(e);
            }else{
                console.error('error happened when search target from local memory,handle type is : drag,target id is : %d',obj.id);
            }
            WEBTools.repaint();
        },
        data_back: function () {
            var i,j;
            var target_id=WEBTools.order_list.pop();
            var e=null;
            for(i= 0,j=WEBTools.pDone_Arr.length;i<j;i++){
                if(WEBTools.pDone_Arr[i].id==target_id&&WEBTools.pDone_Arr[i].changeCount!=0){//找到要撤销的线条数据
                    WEBTools.clearConText();
                    e=WEBTools.pDone_Arr[i];
                    e.changeCount--;
                    if(e.changeCount==0)//最初创建状态
                    {
                        e.display=0;
                        WEBTools.svcId--;
                    }
                    else{//创建之后进行了改动
                        var del=e.Arr_data_handle.pop();
                        if(del.drawingType==500&&del.specialValue.type==0)
                            e.display=1;
                        else{
                            var obj=e.Arr_data_handle[e.Arr_data_handle.length-1];
                            e.init_paint(obj,1);
                        }
                    }
                    WEBTools.repaint();
                }
            }
        },
        data_clear: function () {
            var target_e;
            for(var i=0,j=WEBTools.pDone_Arr.length;i<j;i++){
                target_e=WEBTools.pDone_Arr[i];
                target_e.display=0;
                target_e.changeCount=0;
            }
            WEBTools.repaint();
            WEBTools.svcId=1;
            WEBTools.order_list.length=0;
        },
        data_newHandle: function (obj) {
            if(obj.drawingType==10){
                WEBTools.data_signPen(obj);
            }else if(obj.drawingType==500){
                switch (obj.specialValue.type){
                    case 0:
                        WEBTools.data_newRubber(obj);
                        break;
                    case 1:
                        WEBTools.data_drag(obj);
                        break;
                    case 2:
                        WEBTools.data_reEdit(obj);
                        break;
                    default://unKnow handle
                        //do nothing
                        break;
                }
            }else{//unKnow type
                //do nothing
            }
        },
        e_search:function (id){
            var i=0,j=WEBTools.pDone_Arr.length;
            var tem=null;
            for(;i<j;i++){
                tem=WEBTools.pDone_Arr[i];
                if(tem&&tem.id==id&&tem.display!=0){
                    break;
                }else{
                    tem=null;
                }
            }
            return tem;
        },
        repaint: function () {
            WEBTools.clearConText();

            var e;
            var i=0,j=WEBTools.pDone_Arr.length;
            while(i<j){
                e=WEBTools.pDone_Arr[i];
                e.handle(WEBTools.context);
                i++;
            }
        },
        clearConText:function (){
            WEBTools.context.clearRect(0,0,WEBTools.conf.canvas.width,WEBTools.conf.canvas.height);
            WEBTools.canvas.width=0;
            WEBTools.canvas.width=WEBTools.conf.canvas.width;
        },
        throttle: function (method,context) {//防抖处理
            //避免重复操作
            clearTimeout(method.tid);
            method.tid=setTimeout(function () {
                method.call(context);
            },500);
        },
        toInt10: function (x) {
            var a=null;
            if(x && typeof x==='object' &&
                typeof x.length==='number' &&
                typeof x.splice==='function' &&
                    //判断length属性是否是可枚举的 对于数组 将得到false
                !(x.propertyIsEnumerable('length')))
            {//is Array
                var i= 0,j= x.length;
                a=[];
                for(;i<j;i++){
                    a.push({x:parseInt(x[i],16),y:parseInt(x[++i],16)});
                }
            }else{
                a=parseInt(x,16);
            }
            return a;
        }
    }
    var paint= function (obj) {
        //父类
        this.Arr_data_handle=new Array();//用于存储每一笔的每一步的信息
        this.id=obj.id;
        this.handleType=obj.handleType;
        this.drawingType=obj.drawingType;
        WEBTools.order_list.push(WEBTools.svcId);//创建新的画笔，一定会走paint
        WEBTools.pDone_Arr.push(this);
        WEBTools.svcId++;
    }
    //初始化信息
    paint.prototype.init_paint= function (obj,type) {//根据分析数据去选择操作
        if(!type)
            this.Arr_data_handle.push(obj);
        if(obj.handleType==0){/*增*/
            if(obj.drawingType!=500){
                this.canvasWidth=obj.specialValue.canvasWidth;
                this.canvasHeight=obj.specialValue.canvasHeight;
                //以后会变化的,现在赋默认值
                this.changeCount=1;
                this.display=1;
                this.child_div_W=obj.specialValue.child_div_W;
                this.child_div_H=obj.specialValue.child_div_H;
                this.margin_left=obj.specialValue.margin_left;
                this.margin_top=obj.specialValue.margin_top;
                this.drag_left=0;
                this.drag_top=0;
                if(obj.drawingType==4)//文字
                {
                    this.font_color=obj.specialValue.font.font_color;
                    this.font_size=obj.specialValue.font.font_size;
                    this.font_style=obj.specialValue.font.font_style;
                    this.point_Arr_text=obj.specialValue.str_text;
                }
                else
                {
                    this.color=obj.specialValue.pencil_color;
                    this.size=obj.specialValue.pencil_size;
                    this.point_Arr_text=obj.specialValue.point;
                }
            }else{
                WEBTools.order_list.push(this.id);
                WEBTools.svcId++;
                if(!type)
                    this.changeCount++;
                switch (obj.specialValue.type){
                    case 0://新版橡皮擦
                        this.display=0;
                        break;
                    case 1://拖动
                        this.drag_left=obj.specialValue.drag_left;
                        this.drag_top=obj.specialValue.drag_top;
                        break;
                    case 2://重写
                        this.child_div_W=obj.specialValue.child_div_W;
                        this.child_div_H=obj.specialValue.child_div_H;
                        this.drag_left=obj.specialValue.drag_left;
                        this.drag_top=obj.specialValue.drag_top;
                        this.point_Arr_text=obj.specialValue.str_text;
                        break;
                    default :
                        break;
                }
            }
        }
        else if(obj.handleType==1){
            /*删*/
        }else if(obj.handleType==2){
            /*改*/
        }
    }
    //按类型操作
    paint.prototype.handle= function (target_context) {
        try{
            if(this.display==1){
                switch (this.drawingType){
                    case 0://划线
                        this.canvas_pencil(target_context);
                        break;
                    case 2://长方形
                        this.canvas_square(target_context);
                        break;
                    case 10://荧光笔
                        this.canvas_sign(target_context);
                        break;
                    case 4://文字
                        this.canvas_write(target_context);
                        break;
                    case 3://老版橡皮擦
                        this.canvas_rubber(target_context);
                        break;
                    default :
                        break;
                }
            }
        }catch(e){
            console.error('error happened when paint.prototype.handle : %s',e);
        }

    }
    //画笔
    paint.prototype.canvas_pencil= function (target_context) {
        var s=WEBTools.conf.canvas.width/this.canvasWidth;
        var s2=WEBTools.conf.canvas.width/800;
        target_context.lineCap='round';
        target_context.lineJoin="round";
        target_context.strokeStyle= this.color;
        target_context.lineWidth = this.size*s2;
        target_context.moveTo((this.point_Arr_text[0].x+this.drag_left)*s,(this.point_Arr_text[0].y+this.drag_top)*s);
        target_context.beginPath();
        for(var i=1;i<this.point_Arr_text.length;i++){
            target_context.lineTo((this.point_Arr_text[i].x+this.drag_left)*s,(this.point_Arr_text[i].y+this.drag_top)*s);
        }
        target_context.stroke();
    }
    //长方形
    paint.prototype.canvas_square= function (target_context) {
        var s=WEBTools.conf.canvas.width/this.canvasWidth;
        var s2=WEBTools.conf.canvas.width/800;

        target_context.strokeStyle= this.color;
        target_context.lineJoin="round";
        target_context.lineWidth = this.size*s2;
        target_context.moveTo((this.point_Arr_text[0].x+this.drag_left)*s,(this.point_Arr_text[0].y+this.drag_top)*s);
        target_context.beginPath();
        target_context.lineTo((this.point_Arr_text[1].x+this.drag_left)*s,(this.point_Arr_text[0].y+this.drag_top)*s);
        target_context.lineTo((this.point_Arr_text[1].x+this.drag_left)*s,(this.point_Arr_text[1].y+this.drag_top)*s);
        target_context.lineTo((this.point_Arr_text[0].x+this.drag_left)*s,(this.point_Arr_text[1].y+this.drag_top)*s);
        target_context.lineTo((this.point_Arr_text[0].x+this.drag_left)*s,(this.point_Arr_text[0].y+this.drag_top)*s);
        target_context.closePath();
        target_context.stroke();
    }
    //荧光笔
    paint.prototype.canvas_sign= function (target_context) {
        target_context.save();
        var s=WEBTools.conf.canvas.width/this.canvasWidth;

        target_context.lineCap='round';
        target_context.lineJoin="round";
        target_context.strokeStyle=this.color;
        target_context.globalAlpha=0.3;
        target_context.globalCompositeOperation='destination-over';
        target_context.lineWidth=this.size*WEBTools.conf.canvas.width/800;
        target_context.moveTo((this.point_Arr_text[0].x+this.drag_left)*s,(this.point_Arr_text[0].y+this.drag_top)*s);
        target_context.beginPath();
        for(var i=2;i<this.point_Arr_text.length;i++){
            target_context.lineTo((this.point_Arr_text[i].x+this.drag_left)*s,(this.point_Arr_text[i].y+this.drag_top)*s);
        }
        target_context.stroke();
        target_context.restore();
    }
    //文字
    paint.prototype.canvas_write= function (target_context){
        var theString=this.point_Arr_text;
        var s=WEBTools.conf.canvas.width/this.canvasWidth;
        var hei_point=(this.margin_top+this.drag_top)*s;
        var wid_point=(this.margin_left+this.drag_left)*s;
        var words=[];
        var i,j;

        target_context.font='bold '+Math.round(this.font_size*s)+"px "+WEBTools.conf.font.fontstyle;
        target_context.fillStyle=this.font_color;

        theString.replace(/\r\n/g,'\n');
        words=theString.split(/\n/);

        for(i=0,j=words.length;i<j;i++){
            hei_point+=(this.font_size)*s;
            target_context.fillText(words.shift(),wid_point,hei_point);
        }
    }
    //旧版橡皮擦
    paint.prototype.canvas_rubber= function (target_context) {
        var s=WEBTools.conf.canvas.width/this.canvasWidth;
        var sizerub=WEBTools.conf.pencil.rubbersize;
        target_context.lineCap='round';
        target_context.lineJoin="round";
        for(var i=0;i<this.point_Arr_text.length;i++){
            target_context.clearRect((this.point_Arr_text[i].x)*s-sizerub/2,(this.point_Arr_text[i].y)*s-sizerub/2,sizerub,sizerub);
        }
    }

    var Base64 = {
        // 转码表
        table : [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
            'I', 'J', 'K', 'L', 'M', 'N', 'O' ,'P',
            'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
            'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
            'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
            'w', 'x', 'y', 'z', '0', '1', '2', '3',
            '4', '5', '6', '7', '8', '9', '+', '/'
        ],
        UTF16ToUTF8 : function(str) {
            var res = [], len = str.length;
            for (var i = 0; i < len; i++) {
                var code = str.charCodeAt(i);
                if (code > 0x0000 && code <= 0x007F) {
                    // 单字节，这里并不考虑0x0000，因为它是空字节
                    // U+00000000 – U+0000007F  0xxxxxxx
                    res.push(str.charAt(i));
                } else if (code >= 0x0080 && code <= 0x07FF) {
                    // 双字节
                    // U+00000080 – U+000007FF  110xxxxx 10xxxxxx
                    // 110xxxxx
                    var byte1 = 0xC0 | ((code >> 6) & 0x1F);
                    // 10xxxxxx
                    var byte2 = 0x80 | (code & 0x3F);
                    res.push(
                        String.fromCharCode(byte1),
                        String.fromCharCode(byte2)
                    );
                } else if (code >= 0x0800 && code <= 0xFFFF) {
                    // 三字节
                    // U+00000800 – U+0000FFFF  1110xxxx 10xxxxxx 10xxxxxx
                    // 1110xxxx
                    var byte1 = 0xE0 | ((code >> 12) & 0x0F);
                    // 10xxxxxx
                    var byte2 = 0x80 | ((code >> 6) & 0x3F);
                    // 10xxxxxx
                    var byte3 = 0x80 | (code & 0x3F);
                    res.push(
                        String.fromCharCode(byte1),
                        String.fromCharCode(byte2),
                        String.fromCharCode(byte3)
                    );
                } else if (code >= 0x00010000 && code <= 0x001FFFFF) {
                    // 四字节
                    // U+00010000 – U+001FFFFF  11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else if (code >= 0x00200000 && code <= 0x03FFFFFF) {
                    // 五字节
                    // U+00200000 – U+03FFFFFF  111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else /** if (code >= 0x04000000 && code <= 0x7FFFFFFF)*/ {
                    // 六字节
                    // U+04000000 – U+7FFFFFFF  1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                }
            }

            return res.join('');
        },
        UTF8ToUTF16 : function(str) {
            var res = [], len = str.length;
            var i = 0;
            for (var i = 0; i < len; i++) {
                var code = str.charCodeAt(i);
                // 对第一个字节进行判断
                if (((code >> 7) & 0xFF) == 0x0) {
                    // 单字节
                    // 0xxxxxxx
                    res.push(str.charAt(i));
                } else if (((code >> 5) & 0xFF) == 0x6) {
                    // 双字节
                    // 110xxxxx 10xxxxxx
                    var code2 = str.charCodeAt(++i);
                    var byte1 = (code & 0x1F) << 6;
                    var byte2 = code2 & 0x3F;
                    var utf16 = byte1 | byte2;
                    res.push(
                        String.fromCharCode(utf16)
                    );
                } else if (((code >> 4) & 0xFF) == 0xE) {
                    // 三字节
                    // 1110xxxx 10xxxxxx 10xxxxxx
                    var code2 = str.charCodeAt(++i);
                    var code3 = str.charCodeAt(++i);
                    var byte1 = (code << 4) | ((code2 >> 2) & 0x0F);
                    var byte2 = ((code2 & 0x03) << 6) | (code3 & 0x3F);
                    utf16 = ((byte1 & 0x00FF) << 8) | byte2
                    res.push(String.fromCharCode(utf16));
                } else if (((code >> 3) & 0xFF) == 0x1E) {
                    // 四字节
                    // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else if (((code >> 2) & 0xFF) == 0x3E) {
                    // 五字节
                    // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else /** if (((code >> 1) & 0xFF) == 0x7E)*/ {
                    // 六字节
                    // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                }
            }

            return res.join('');
        },
        encode : function(str) {
            if (!str) {
                return '';
            }
            var utf8    = this.UTF16ToUTF8(str); // 转成UTF8
            var i = 0; // 遍历索引
            var len = utf8.length;
            var res = [];
            while (i < len) {
                var c1 = utf8.charCodeAt(i++) & 0xFF;
                res.push(this.table[c1 >> 2]);
                // 需要补2个=
                if (i == len) {
                    res.push(this.table[(c1 & 0x3) << 4]);
                    res.push('==');
                    break;
                }
                var c2 = utf8.charCodeAt(i++);
                // 需要补1个=
                if (i == len) {
                    res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);
                    res.push(this.table[(c2 & 0x0F) << 2]);
                    res.push('=');
                    break;
                }
                var c3 = utf8.charCodeAt(i++);
                res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);
                res.push(this.table[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]);
                res.push(this.table[c3 & 0x3F]);
            }

            return res.join('');
        },
        decode : function(str) {
            if (!str) {
                return '';
            }

            var len = str.length;
            var i   = 0;
            var res = [];

            while (i < len) {
                code1 = this.table.indexOf(str.charAt(i++));
                code2 = this.table.indexOf(str.charAt(i++));
                code3 = this.table.indexOf(str.charAt(i++));
                code4 = this.table.indexOf(str.charAt(i++));

                c1 = (code1 << 2) | (code2 >> 4);
                c2 = ((code2 & 0xF) << 4) | (code3 >> 2);
                c3 = ((code3 & 0x3) << 6) | code4;

                res.push(String.fromCharCode(c1));

                if (code3 != 64) {
                    res.push(String.fromCharCode(c2));
                }
                if (code4 != 64) {
                    res.push(String.fromCharCode(c3));
                }

            }

            return this.UTF8ToUTF16(res.join(''));
        }
    };

    exports.dataRebuild= function (obj) {
        if(obj.type=='data'){
            try{
                if(!WEBTools.context){
                    WEBTools.init();
                }
                if(obj.subType=='wbPosition'){//data of mouse
                    WEBTools.data_mouse(obj.data);
                }else if(obj.subType=='wbData'){//data of Board
                    if(obj.data.operation=='add'||obj.data.operation=='syn'){//handle add
                        if(obj.data.operation=='syn'){
                            WEBTools.pDone_Arr=[];
                            WEBTools.order_list=[];
                            WEBTools.svcId=1;
                        }
                        var i= 0,j=obj.data.items.length;
                        for(;i<j;i++){
                            if(obj.data.items[i]!=undefined){
                                switch (obj.data.items[i].itemType){
                                    case 'line':
                                        WEBTools.data_pencil(obj.data.items[i]);
                                        break;
                                    case 'rectangle':
                                        WEBTools.data_rectangle(obj.data.items[i]);
                                        break;
                                    case 'text':
                                        WEBTools.data_text(obj.data.items[i]);
                                        break;
                                    case 'eraser':
                                        WEBTools.data_rubber(obj.data.items[i]);
                                        break;
                                    case 'newHandler':
                                        WEBTools.data_newHandle(JSON.parse(obj.data.items[i].jsonText));
                                        break;
                                    default:
                                        console.log('unKnow handle type from svc,type is : %s',obj.data.items[i].itemType);
                                        break;
                                }
                            }else{
                                console.log('null items from svc,type is : %s',obj.data.operation)
                            }
                        }
                    }else if(obj.data.operation=='delete'){//handle delete
                        WEBTools.data_back(obj.data.items[0]);
                    }else if(obj.data.operation=='clear'){//handle clear
                        WEBTools.data_clear();
                    }else{//other handle
                        //no handle
                    }

                }else{//other data
                    //no handle
                }
            }catch (e){
                console.error('error happened when resetData : %s',e);
            }
        }else{
            console.error('error type : %s',obj.type);
        }
    }

    exports.updateData= function () {
        WEBTools.throttle(WEBTools.reviewData);
    }

    window.paintWebUpdateData= function () {
        WEBTools.throttle(WEBTools.reviewData);
    }

    exports.initBind= function () {
        zTouch.bindSwiper();
        window.touchSwiperInit();
        if(!WEBTools.context){
            WEBTools.init();
        }
    }
});
define("userSlide",['touchSwiper','shareWeixin','simpScroller'],function (require, exports, module) {

    var touchSwiper = require('touchSwiper');
    var shareWeixin = require('shareWeixin');
    var simpScroller = require('simpScroller');

    var userSlide = {

        sliderObj:null,
        landcount:0,
        portcount:0,
        sumW:0,
        total:0,
        sumL:0,
        txtkey:false,
        //横屏下当前第几屏
        curState:1,
        //避免重复绑定划动事件(横屏下标记)
        heng:0,
        stuPage2H:0,
        stuPageH:0,
        megTimeout:null,
        swiperReinit: function(){

            window.setTimeout(function(){

                if(common.playKind == 0 || common.playKind == 2){
                    touchSwiper.reinit();
                } else {

                    touchSwiper.reinitAudio();
                }

            },100)

        },

        //聊天内容上下滚动事件
        chatTouch:function(container, parentContainer) {

            simpScroller.simpscroller(document.getElementById(parentContainer));

        },
        //横屏情况下上下翻页事件
        pageSlide: function () {

            //视频区域中的换页
            $("#btn_next_header").click(function(){

                if(common.playKind == 0 || common.playKind == 2){

                    $("#btn_prev").html("&lt; 视频")
                                    .css({"display":"block","left":"15px"});

                    $("#btn_next").html("讨论 &gt;")
                                    .css("display","block");

                    $("#btn_next_header").hide();

                    $("#pagenavi li").eq(0).find("span").addClass("active");
                    $("#pagenavi li").eq(1).find("span").removeClass("active");
                    $("#pagenavi li").eq(2).find("span").removeClass("active");

                    //翻页到教材

                    $(".mid_container").animate({"left":"-"+$("#stuPage2").width()+"px"},400);

                    userSlide.curState = 2;

                } else {

                    $("#btn_prev").html("&lt; 教材")
                                    .css({"display":"block","left":"15px"});

                    $("#btn_next").html("助手 &gt;")
                                    .css({"display":"block","left":($(window).width()-10-45)+"px"});

                    $("#pagenavi li").eq(0).find("span").addClass("active");
                    $("#pagenavi li").eq(1).find("span").removeClass("active");

                    $("#btn_next_header").hide();

                    //翻页到讨论

                    $(".mid_container").animate({"left":"-"+$("#stuPage2").width()+"px"},400);
                    userSlide.curState = 2;

                }
            })

            $("#btn_prev").click(function(){

                //回到视频区域
                if(userSlide.curState == 2){

                    $(".mid_container").animate({"left":"0px"},400);
                    $("#btn_next_header").css("display","block");
                    $("#btn_prev").hide();
                    $("#btn_next").hide();

                    //标签处于选中状态
                    $("#pagenavi li").eq(0).find("span").addClass("active");
                    $("#pagenavi li").eq(1).find("span").removeClass("active");
                    $("#pagenavi li").eq(2).find("span").removeClass("active");

                }
                if(userSlide.curState == 3){

                    $(".mid_container").animate({"left":"-"+$("#stuPage2").width()+"px"},400);

                    if(common.playKind == 0 || common.playKind == 2) {

                        $("#btn_prev").html("&lt; 视频")
                            .css({"left": "15px"});
                        $("#btn_next").html("讨论 &gt;")
                            .css({"display": "block", "left": ($(window).width() - 10 - 45) + "px"});

                        //标签处于选中状态
                        $("#pagenavi li").eq(0).find("span").addClass("active");

                        $("#pagenavi li").eq(1).find("span").removeClass("active");
                        $("#pagenavi li").eq(2).find("span").removeClass("active");

                    } else {

                        $("#btn_prev").html("&lt; 教材")
                                       .css({"left": "15px"});
                        $("#btn_next").html("助手 &gt;")
                                        .css({"display": "block", "left": ($(window).width() - 10 - 45) + "px"});

                        //标签处于选中状态
                        $("#pagenavi li").eq(0).find("span").addClass("active");
                        $("#pagenavi li").eq(1).find("span").removeClass("active");
                    }
                }

                if(userSlide.curState == 4){

                    $(".mid_container").animate({"left":"-"+($("#stuPage2").width()+$("#contain_course").width())+"px"},400);

                    $("#btn_prev").html("&lt; 教材")
                        .css({"left":"15px"});
                    $("#btn_next").html("助手 &gt;")
                        .css({"display":"block","left":($(window).width()-10-45)+"px"});

                    //标签处于选中状态
                    $("#pagenavi li").eq(1).find("span").addClass("active");

                    $("#pagenavi li").eq(0).find("span").removeClass("active");
                    $("#pagenavi li").eq(2).find("span").removeClass("active");

                    document.body.addEventListener('touchmove', userSlide.preDefault);
                }

                userSlide.curState = userSlide.curState - 1;

            })
            $("#btn_next").click(function(){

                if(userSlide.curState == 2){

                    if(common.playKind == 0 || common.playKind == 2) {

                        var totalW = $("#stuPage2").width() + $("#contain_course").width();

                        //标签处于选中状态
                        $("#pagenavi li").eq(1).find("span").addClass("active");

                        $("#pagenavi li").eq(0).find("span").removeClass("active");

                        $("#pagenavi li").eq(2).find("span").removeClass("active");

                        $("#btn_prev").html("&lt; 教材")
                            .css({"display": "block", "left": "15px"});

                        $("#btn_next").html("助手 &gt;")
                            .css({"display": "block", "left": ($(window).width() - 10 - 45) + "px"});

                        $("#btn_next_header").hide();

                    } else {

                        var totalW = $("#stuPage2").width() + $("#contain_chat").width();

                        //标签处于选中状态
                        $("#pagenavi li").eq(1).find("span").addClass("active");

                        $("#pagenavi li").eq(0).find("span").removeClass("active");

                        $("#btn_prev").html("&lt; 讨论")
                                        .css({"display": "block", "left": "15px"});

                        $("#btn_next").hide();
                    }
                }
                if(userSlide.curState == 3){

                    var totalW = $("#stuPage2").width() + $("#contain_course").width() + $("#contain_chat").width();
                    //标签处于选中状态
                    $("#pagenavi li").eq(2).find("span").addClass("active");

                    $("#pagenavi li").eq(0).find("span").removeClass("active");

                    $("#pagenavi li").eq(1).find("span").removeClass("active");

                    $("#btn_prev").html("&lt; 讨论")
                                    .css({"display":"block","left":"15px"});

                    $("#btn_next").hide();
                    $("#btn_next_header").hide();

                    document.body.removeEventListener('touchmove', userSlide.preDefault);
                }

                $(".mid_container").animate({"left":"-"+totalW+"px"},400);

                userSlide.curState = userSlide.curState + 1;

            })

        },

        //监听屏幕横竖屏状态
        windowListenerSize: function(){

            document.getElementById("beforeContainer").addEventListener('touchmove', userSlide.preDefault);

            //横竖屏切换时
            //暂时不让ipad有横屏模式（以后优化）
            if(common.getAppVersion().indexOf("iPad") < 0){

                if(common.deviceType() == "android"){

                    //安卓手机为4.2版本的横屏下orientationchange事件没响应，所以改为resize事件
                    if(common.getAppVersion().indexOf("Android 4.2") > 0){

                        window.addEventListener("resize", userSlide.pageTouch, false);
                    } else {

                        window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", userSlide.pageTouch, false);
                    }
                } else {

                    window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", userSlide.pageTouch, false);
                }

            }

            //初始化
            userSlide.pageTouch();

            //当聊天输入框输入内容时，按钮变黄色
            document.getElementById('chatTxt').addEventListener('input', function(e){

                var value = $.trim(e.target.value);

                if (value != "") {

                    $("#chatSend img").attr("src", common.imgUrl+"send.png");

                } else {

                    $("#chatSend img").attr("src", common.imgUrl+"send_grey.png");

                }
            });

            //讨论区的上下滚动
            userSlide.chatTouch("userChatBox", "wrapper");

            //课堂助手的上下滚动
            userSlide.chatTouch("helper_item", "helper_box");

            userSlide.setHelperBox();

        },
        setHelperBox:function () {

            var $chi = $("#helper_item").find("dl");

            var chiLen = $chi.length;
            var itmeH = 0;

            for(var i=0;i<chiLen;i++){

                var marTop = parseInt($($chi[i]).css("margin-top"));
                var pdgTop = parseInt($($chi[i]).css("padding-top"));
                var pdgBom = parseInt($($chi[i]).css("padding-bottom"));

                var totalH = parseInt($($chi[i]).height() + marTop + pdgTop + pdgBom);
                itmeH = totalH + itmeH;

            }

            $("#helper_item").css("height",itmeH+"px");
        },
        //阻止默认事件
        preDefault:function(event){

            event.preventDefault();

        },
        //横屏下的显示效果
        LandscapeShow:function(){

            $("#chatTxt").blur();

            var wSection = 4,   //总共3部分
                w2Section = 3;  //教材和讨论助手共3部分

            //音频模式
            if(common.playKind == 1){

                wSection = 3;
                w2Section = 2;

            }

            var totalW = $(window).width() * wSection;

            $("#beforeContainer").css({"height": $(window).height() + "px", "width": $(window).width() + "px"});

            $(".mid_container").css({"height": $(window).height() + "px", "width": totalW + "px", "left": "0"});

            $("#contain_course,#contain_chat,#helper_box").show();

            $(".video_tip").hide();
            $("#megTipBox").hide();

            $(".video_box").width($(window).width()+"px");
            $(".video_box").height($(window).height()+"px");

            $("#stuPage2").css({"height": $(window).height() + "px", "width": $(window).width() + "px"});

            $("#stuPage").css({"height": $(window).height() + "px", "width": $(window).width() * w2Section + "px", "display":"block"});

            if(common.playKind == 1){

                $("#slider2").css({"z-index":"auto","top":"0px"});
                //userSlide.swiperReinit();
            }

            $("#contain_course,#contain_chat,#helper_box").css({

                "height": $(window).height() + "px",
                "width": $(window).width() + "px"
            });

            //视频模式
            if(common.playKind == 0 || common.playKind == 2){
                $("#contain_course").css({"left": "0px"});
                $("#contain_chat").css({"left": $("#contain_course").width() + "px"});
                $("#helper_box").css({"left": $("#contain_course").width()+$(window).width() + "px"});
            } else {
                $("#contain_chat").css({"left": "0px"});
                $("#helper_box").css({"left": $(window).width() + "px"});
            }

            //聊天区域的固定高度
            $("#slider").height($("#stuPage").height()+"px");

            //聊天区域的高度
                window.setTimeout(function () {

                    $("#wrapper").height($("#contain_chat").height() - $(".chat_write_box").height() + "px");
                }, 10)

            //教材恢复原状

            userSlide.swiperReinit();

            //当竖屏下弹出教材时，转向横屏需要马上划动到教材页面

            if ($("#zoomBtn").hasClass("small")) {

                $("#zoomBtn").addClass("big")
                               .removeClass("small");

                //当视频播放时，横屏下手机会优先显示视频，自动划动不起作用，所以要加上延时

                if(common.playKind == 0 || common.playKind == 2){

                    window.setTimeout(function () {

                        $("#btn_next_header").click();

                    }, 100)
                }


            }
            //避免横屏下2次触发resize事件
            if (common.deviceType() == "iphone") {

                if (userSlide.sumW >= 1) return;
            }

            //直播页显示收藏和分享蒙层后，横竖屏转换时
            shareWeixin.showcanglike();

            if (userSlide.heng <= 0) {        //避免重复绑定划动事件

                //用手划动事件
                $('#stuPage2').on("swipeLeft",function (event) {

                    //避免竖屏下的划动

                    if (common.isLandOrPort() != "landscape") return;
                    window.setTimeout(function(){

                        $("#btn_next_header").click();

                    },100)

                })

                $('#contain_course,#wrapper').on("swipeLeft",function (event) {

                    //避免竖屏下的划动

                    if (common.isLandOrPort() != "landscape") return;

                    window.setTimeout(function(){

                        $("#btn_next").click();

                    },100)

                })
                $('#contain_course,#wrapper').on("swipeRight",function () {

                    //避免竖屏下的划动
                    if (common.isLandOrPort() != "landscape") return;

                    window.setTimeout(function(){
                        $("#btn_prev").click();
                    },100)

                })

                $('#helper_box').on("swipeRight",function () {

                    if (common.isLandOrPort() != "landscape") return;

                    window.setTimeout(function(){
                        $("#btn_prev").click();
                    },100)

                })
            }


            userSlide.sumW++;

            userSlide.heng = 1;
        },

        //touch事件
        pageTouch: function(event){

            //设置横竖屏转换时间，如果软键盘弹起，转换时则为700，没弹起，则为300
            var shortT = 300;
            var myInput = document.getElementById('chatTxt');
            if (myInput == document.activeElement) {
                shortT = 700
            }

            if(common.isLandOrPort() == "landscape") {

                userSlide.sumL = 0;

                if(common.deviceType() == "android"){

                    if (userSlide.sumW >= 1) return;
                }

                //避免zepto swipe 在android设备上无效

                if($("#zoomBtn").hasClass("small")){

                    $("#mask").remove();

                    $("#slider").css({"z-index":"auto","top":"0px"});

                    $("#videoBox").css("height","100%");

                }

                $("#btn_next_header").css("display","block");
                $("#zoomBtn").hide();
                $("#pagenavi").hide();
                $("#largeCourseBtn").hide();
                $("#btn_prev").hide();
                $("#megTipBox").hide();

                if (common.playKind == 1) {
                    $("#stuPage").hide();

                }
                //设置时间长些，阻止竖屏下软键盘弹起后，转向横屏后，软键盘不能马上消失的问题。

                window.setTimeout(function () {

                    userSlide.LandscapeShow();

                }, common.deviceType() == "android" ? shortT:0)

                //竖屏情况下
            } else {

                var upPer = 0.51, downPer = 0.49;

                //音频模式下比率变化
                if (common.playKind == 1) {

                    upPer = 0.346;
                    downPer = 0.654;

                    $("#btn_next_header").html("讨论 &gt;");

                }

                userSlide.sumW = 0;
                userSlide.curState = 1;

                $("#chatTxt").blur();

                //避免竖屏下2次触发resize事件
                if (userSlide.sumL >= 1) return;

                $("#btn_prev,#btn_next,#btn_next_header").hide();
                $("#zoomBtn").show();
                $("#pagenavi").show();
                $("#largeCourseBtn").show();
                $("#megTipBox").show();

                //延时显示，否则从横屏转到竖屏时，样式不能马上转变过来
                window.setTimeout(function(){

                    $("#beforeContainer").css({"height": $(window).height()+"px", "width": "100%"});

                    $(".mid_container").css({"height": $(window).height()+"px", "width": "100%","left":"0"});
                    $(".video_tip").show();

                    //上半部的高度
                    if(userSlide.stuPage2H <=0){

                        userSlide.stuPage2H = $(window).height() * upPer;

                        //纯音频模式下，上半部分的高度为教材图片的高度
                        if (common.playKind == 1) {
                            userSlide.stuPage2H = $("#courseShow img").height();
                        }
                    }
                    $("#stuPage2").css({"height": userSlide.stuPage2H+"px","width":"100%","left":"0"});

                    //下半部的高度
                    //视频模式下,stuPageH为下半部分的高度（包括导航栏）
                    //音频模式下，stuPageH为下半部分的高度（包括显示播放信息的隔断条目，导航栏）
                    if(userSlide.stuPageH <=0){

                        if (common.playKind == 1) {
                            userSlide.stuPageH = $(window).height() - userSlide.stuPage2H;
                        } else {
                            userSlide.stuPageH = $(window).height() * downPer
                        }

                    }

                    //中间显示播放信息的隔断条目
                    if (common.playKind == 1) {
                        var midPage = $("#megTipBox").height();
                    } else {
                        var midPage = 0;
                    }

                    $("#stuPage").css({"height": (userSlide.stuPageH-midPage)+"px","width": "100%","left":"0"});

                    $("#contain_course,#contain_chat,#helper_box").css({"height": "100%","width": "100%","left":"0"});

                    //视频区域的固定高度和宽度
                    $(".video_box").height($("#liHeader").height()-$(".video_tip").height()+"px");
                    $(".video_box").width($(window).width()+"px");

                    $("#slider").height($("#stuPage").height() - $("#pagenavi").height() + "px");

                    if(!common.classBan){

                        $("#wrapper").height($("#slider").height() - $(".chat-box-back").height() + "px");
                        console.log("竖屏情况下聊天区域高度:%s",$("#wrapper").height());

                    }

                    //聊天区域的高度

                    if (common.playKind == 1) {

                        $("#zoomBtn").attr("src", common.imgUrl+"fangda.png");
                    }

                    //根据导航选中的状态，显示教材和聊天区

                    var $list = $("#slider .box01_list");
                    if($("#pagenavi li").eq(0).find("span").hasClass("active")){

                        $list.children().eq(0).show();
                        $list.children().eq(0).siblings().hide();

                        //教材恢复原状
                        userSlide.swiperReinit();
                    }

                    if($("#pagenavi li").eq(1).find("span").hasClass("active")){

                        $list.children().eq(1).show();
                        $list.children().eq(1).siblings().hide();

                        if (common.playKind == 1) {
                            //教材恢复原状
                            userSlide.swiperReinit();
                        }

                    }

                    if($("#pagenavi li").eq(2).find("span").hasClass("active")){

                        $("#contain_course").hide();
                        $("#contain_chat").hide();
                        $("#helper_box").show();
                    }

                    $("#courseShow .img").css("height", "auto");

                    document.body.removeEventListener('touchmove', userSlide.preDefault);

                    userSlide.sumL++;
                    userSlide.txtkey = false;

                },common.deviceType() == "android" ? shortT:300)

                //直播页显示收藏和分享蒙层后，横竖屏转换时
                    shareWeixin.showcanglike();
            }

        },

        //竖屏情况下教材和讨论区的切换效果
        transformPage: function(){

            //singleTap
            $("#pagenavi li").click(function(e) {

                $(this).find("span").addClass("active");
                $(this).siblings().find("span").removeClass("active");

                var ind = $(this).index();
                var $list = $("#slider .box01_list");

                $list.children().eq(ind).show();
                $list.children().eq(ind).siblings().hide();

                //视频模式下，索引为0的为教材；纯音频模式下，索引为0的是讨论区
                if (ind == 0 && common.playKind != 1) {
                    //教材恢复原状
                    userSlide.swiperReinit();
                }

            })

        },
        //教材的放大和缩小事件
        zoomPage: function(){

            //视频模式下
            $("#zoomBtn").click(function(){

                var w = $("#beforeContainer").width();
                var h = $("#beforeContainer").height();

                str = "<div id='mask' class='mask'></div>";

                var sliderDiv = "#slider";

                if (common.playKind == 1){
                    sliderDiv = "#slider2";
                }
                if($(this).hasClass("big")){

                    $(this).addClass("small")
                        .removeClass("big");

                    $(".zoomAudio").attr("src",common.imgUrl+"suoxiao.png");

                    $("body").append(str);

                    //音击蒙板也可以缩小教材
                    $("#mask").click(function(){

                        $("#zoomBtn").addClass("big")
                            .removeClass("small");

                        $("#mask").remove();

                        $(sliderDiv).css({"z-index":"auto","top":"0px"});
                        $(".zoomAudio").attr("src",common.imgUrl+"fangda.png");
                        $("#videoBox").css("height","100%");

                        userSlide.swiperReinit();

                    })

                    var $top = parseInt(h/2) - parseInt($(sliderDiv).height()/2);

                    if (common.playKind == 0 || common.playKind == 2){

                        $(sliderDiv).css({"z-index":"100000","top":'-'+$top+"px"});
                    } else {
                        
                        $(sliderDiv).css({"z-index":"100000","top":$top+"px"});
                    }


                    $("#videoBox").css("height","0");

                } else {

                    $(this).addClass("big")
                        .removeClass("small");
                    $(".zoomAudio").attr("src",common.imgUrl+"fangda.png");

                    $("#mask").remove();

                    $(sliderDiv).css({"z-index":"auto","top":"0px"});

                    $("#videoBox").css("height","100%");

                    userSlide.swiperReinit();
                }

            })

        }
    }

    exports.pageSlides = function(){

        userSlide.pageSlide();
    }
    exports.zoomPages = function(){

        userSlide.zoomPage();
    }
    exports.transformPages = function(){

        userSlide.transformPage();

    }

    exports.windowListenerSizes = function(){

        userSlide.windowListenerSize();
    }

});
define("handShake",['chat','paintWeb'],function (require, exports, module) {

    var chat = require('chat');
    var paint=require('paintWeb');

    //定义连接对象
    var initConnect = {

        IsCon : false,

        //监听后端返回数据
        dataServer : function(dataObj){

            console.log("服务端返回的对象参数：%o",dataObj);

            //登录成功
            if(dataObj.type == "login") {

                if(dataObj.subType == "loginAck") {

                    if (dataObj.data.responseCode == "success") {

                        this.IsCon = true;
                        common.IsCon = true;
                        //系统当前时间
                        common.curSysTime = common.Converto10(dataObj.data.currentTime);

                        //当前在线人数
                        common.onlineCount = common.Converto10(dataObj.data.personNumber);

                        $(".onlineSpan").html(common.onlineCount);

                        //当前人数大于教室最大容量时，提示且让学生退出教室
                        if(common.teaCapacity < common.onlineCount){

                            alert("教室人数已满");

                            if(common.isWeixin()){

                                WeixinJSBridge.call('closeWindow');

                            } else {
                                window.history.back();

                            }

                            return;
                        }

                        //判断是否是老师和助教

                        var $ids = dataObj.data.specialIds;

                        for(var i in $ids){

                            var se = $ids[i].role;

                            if(se == "teacher"){
                                common.teacherIds = common.Converto10(i);
                                common.userAllInfo.res.meetInfo.teaId = common.teacherIds;
                            }

                            if(se == "administrator"){
                                common.helperId = common.Converto10(i);
                            }


                        }

                        //如果当前系统时间大于开课时间，则直接进入视频
                        if(common.curSysTime > common.openClassTime && common.isClassEnd != 0){

                            common.classPlaying = true;

                        }
                        if(common.teacherIds > 0){
                            common.classPlaying = true;

                        }

                        //只有音频时，音频控件隐藏（不显示音频的界面）///////////////////////////////////////////
                        if(common.playKind == 1){

                            //播放声音
                            common.startOpenClass();

                            //老师离开
                            if(common.isClassEnd == 0 && common.teacherIds <= 0){

                                common.showLeavePage();
                            }

                            //显示正在直播的提示
                            if(common.classPlaying) {

                                $("#zhiboing").show()
                                                .siblings("span").hide();

                                return;
                            }


                            //倒计时
                            if(!common.classPlaying) {

                                $("#timeSapn").show()
                                    .siblings("span").hide();

                                //上课倒计时
                                common.countDown();

                                return;

                            }

                            //return;
                        }

                        ///////////////////////////////////////////////////////////////////////////////

                        //如果课程结束且老师也没进入教室且当前是视频模式，则显示老师不在的提示
                        if(common.isClassEnd == 0 && common.teacherIds <= 0){

                            $("#intoPage").hide();
                            common.showLeavePage();

                            return;
                        }

                        if(common.classPlaying) {

                            $("#intoPage").hide();

                            common.startOpenClass();

                        }
                        //倒计时
                        if(!common.classPlaying) {

                            $("#intoPage").hide();

                            $("#headerPage").addClass("dis-flex");
                            //上课倒计时
                            common.countDown();

                        }


                    } else {

                        common.IsCon = false;
                        common.tipShow(common.warnInfo.netError);
                    }
                }
            }

            if(dataObj.type == "data") {

                switch (dataObj.subType){

                    //聊天
                    case 'chat':

                        if(dataObj.data){

                            //参数1表示聊天内容，参数2表示身份标识
                            //老师：1，学生：2，自己：21，助教：3

                            chat.chatInfo_add(dataObj.data, common.customerType(dataObj.data))
                        }

                        break;

                    //白板翻页
                    case 'wbFlip':

                        var picUrl = common.userAllInfo.res.meetInfo.pdfPath;

                        var curPage = (common.Converto10(dataObj.data.currentPage)) + 1;

                        common.userAllInfo.res.meetInfo.totalPages = common.Converto10(dataObj.data.totalPage);

                        //根据返回的当前页数，更新当前图片地址
                        if(picUrl){

                            picUrl = $("#courseShow .img").attr("src");

                            $("#courseShow .img").attr("src", picUrl.replace(/_\d*.jpg/, "_"+curPage+".jpg"));
                        }

                        break;

                    //白板数据
                    case 'wbData':

                        paint.dataRebuild(dataObj);
                        break;

                    //光标指针位置
                    case 'wbPosition':
                        paint.dataRebuild(dataObj);
                        break;

                }

            }

            //禁言或者踢人
            if(dataObj.type == "action"){

                if(dataObj.subType == "ban") {

                    common.banMessage(dataObj.data);

                }
                //踢人
                if(dataObj.subType == "kick"){

                    common.userKicked(dataObj.data);

                }
            }

            //网络异常或者登录失败
            if(dataObj.type == "error") {

                if(dataObj.subType == "svcError") {

                    this.IsCon = false;
                    common.conNormal = false;
                }
            }

            //下行有人进入教室和有人离开教室
            if(dataObj.type == "notify") {

                if(dataObj.subType == "enterClass") {

                    var $ids = dataObj.data.userIds;

                    for(var i in $ids){

                        var se = $ids[i].role;

                        if(se == "administrator"){
                            common.helperId = common.Converto10(i);
                        }

                        common.chgOnlineNum(1);

                        if(se == "teacher"){

                            common.teacherIds = common.Converto10(i);
                            common.userAllInfo.res.meetInfo.teaId = common.teacherIds;

                            common.classPlaying = true;

                            $("#intoPage").hide();
                            common.startOpenClass();

                            console.log("老师ID:%s",common.teacherIds);
                        }
                    }

                }
                if(dataObj.subType == "leaveClass") {


                    var $ids = dataObj.data.userIds;

                    common.teaLeaveTime = common.Converto10(dataObj.data.currentTime);

                    for(var i in $ids){

                        common.chgOnlineNum(-1);

                        //如果是老师离开则，显示离开页面

                        if(common.teacherIds == common.Converto10($ids[i])){

                            common.showLeavePage();

                        }

                    }

                }
            }

        }

    }

    //服务端调用该函数，且返回值于dataObj中
    window.handleShakedataServer = function(dataObj){

        initConnect.dataServer(dataObj);
    }

});
define('touchSwiper',['paintWeb'],function (require, exports, module) {
    var paint=require('paintWeb');
    var args={
        other:$('#courseShow'),
        canvasCon:document.getElementById('paint_canvas'),//paint_canvas
        iniAngle:180,
        beforeCallback:function(tPoint){
            var _this=tPoint.self,
                _width=_this.find("img").width();
            tPoint.setAttr("iniWidth",_width);
        },
        sCallback:function(tPoint){
            //e.touches.length;
        },
        mCallback:function(tPoint,e){
            var _this=tPoint.self;//paint_list
            var _other=null;//$('#courseShow')
            var _canvas=null;
            if(tPoint.other!=undefined){
                _other=tPoint.other;
            }
            if(tPoint.canvasCon!=undefined){
                _canvas=tPoint.canvasCon;
            }
            if(tPoint.mutiTouch){//多点
                if(!tPoint.startScale){
                    tPoint.setAttr("startScale",0.5);
                }else{
                    var curWid= 0,//$('#courseShow')的宽
                        curHei= 0,//$('#courseShow')的高
                        curLeft= 0,//$('#courseShow')当前左移距离
                        curTop= 0,//$('#courseShow')当前上移距离
                        conWid=$('#contain_course').width(),//最外层的宽高，基准，overflow scroll
                        conHei=$('#contain_course').height();
                    var _curScale=tPoint.startScale*tPoint.scale;
                    if(_other!=null){
                        if(_curScale<1){
                            _curScale=1;
                        }
                        _other.css("width",_curScale*100+"%");
                        curWid=_other.width();
                        curHei=_other.height();
                        curLeft=parseInt(_other.css('margin-left').replace('px',''));
                        curTop=parseInt(_other.css('margin-top').replace('px',''));
                        if(curWid<=conWid){//横向居中处理
                            _other.css('margin-left',(conWid-curWid)/2);
                        }else if(curLeft<0&&curWid+curLeft<conWid){//右面留白的情况
                            _other.css('margin-left',curWid-conWid);
                        }else if(curLeft>0){//左面留白的情况
                            _other.css('margin-left',0);
                        }
                        if(curHei<conHei){//纵向居中处理
                            _other.css('margin-top',(conHei-curHei)/2);
                        }else if(curTop<0&&curHei+curTop<conHei){//下面留白的情况
                            _other.css('margin-top',curHei-conHei);
                        }else if(curTop>0){//上面留白的情况
                            _other.css('margin-top',0);
                        }
                        _this.css({
                            'width':_other.width(),
                            'height':_other.height(),
                            'left':_other.css('margin-left'),
                            'top':_other.css('margin-top')
                        });
                        if(_canvas!=null){
                            _canvas.width=_other.width();
                            _canvas.height=_other.height();
                        }
                        window.paintWebUpdateData();
                    }
                    tPoint.setAttr("curScale",_curScale);
                }
                e.preventDefault();
                e.stopPropagation();
            }else{//单点
                var tWid= 0,//记录横向差值
                    tHei= 0,//记录竖向差值
                    curLeft= 0,//当前左移距离
                    curTop= 0,//当前上移距离
                    conWid=$('#contain_course').width(),//最外层的宽高，基准，overflow scroll
                    conHei=$('#contain_course').height();
                tWid=conWid-_this.width();
                tHei=conHei-_this.height();
                curLeft=tPoint.startLeft+tPoint.xLen;
                curTop=tPoint.startTop+tPoint.yLen;
                if(Math.abs(curLeft)+conWid<=_this.width()||Math.abs(curTop)+conHei<=_this.height()){
                    if(curLeft<=0&&Math.abs(curLeft)+conWid<=_this.width()){
                        _this.css('left', curLeft);
                    }
                    if(curTop<=0&&Math.abs(curTop)+conHei<=_this.height()){
                        _this.css('top', curTop);
                    }
                    if(tPoint.direction=='left'){
                        if(Math.abs(curLeft)+conWid<_this.width()){
                            e.preventDefault();
                            e.stopPropagation();
                        }
                    }else if(tPoint.direction=='right'){
                        if(curLeft<0){
                            e.preventDefault();
                            e.stopPropagation();
                        }
                    }
                }
                if(_other!=undefined){
                    _other.css({
                        'margin-left':_this.css('left'),
                        'margin-top':_this.css('top')
                    });
                }
            }
        },
        eCallback:function(tPoint){
            if(tPoint.curScale){
                tPoint.setAttr("startScale",tPoint.curScale);
            }
        }
    }
    window.touchSwiperInit= function () {
        var courseTop= 0,
            paintTop= 0,
            offSet=$('#courseShow')[0].parentElement.offsetHeight-$('#courseShow').height();
        courseTop=(offSet>0)?(offSet/2):0;
        $('#courseShow').css({
            'margin-left':'0px',
            'margin-top': courseTop+'px'
        });
        $('.paint_list').css({
            'width':$('#courseShow').width(),
            'height':$('#courseShow').height(),
            'top':$('#courseShow').css('margin-top'),
            'left':$('#courseShow').css('margin-left')
        });
        var canvas=document.getElementById('paint_canvas');
        canvas.width=$('#courseShow').width();
        canvas.height=$('#courseShow').height();
        paint.updateData();
        $(".paint_list").Swipe(args);
    };
    //视频模式下
    exports.reinit= function () {

        var parentCon=$('#courseShow')[0].parentElement;
        $('#courseShow').width(parentCon.offsetWidth);
        var offSet=parentCon.offsetHeight-$('#courseShow').height();
        var courseTop=(offSet>0)?(offSet/2):0;
        $('#courseShow').css({
            'margin-left':0,
            'margin-top': courseTop+'px'
        });
        $('.paint_list').css({
            'width':$('#courseShow').width(),
            'height':$('#courseShow').height(),
            'top':$('#courseShow').css('margin-top'),
            'left':$('#courseShow').css('margin-left')
        });
        var canvas=document.getElementById('paint_canvas');
        canvas.width=$('#courseShow').width();
        canvas.height=$('#courseShow').height();
        paint.updateData();
    }
    //音频模式下
    exports.reinitAudio= function () {

        var parentCon=$('#courseShow')[0].parentElement;
        $('#courseShow').width(parentCon.offsetWidth);
        var offSet=parentCon.offsetHeight-$('#courseShow').height();
        var courseTop=(offSet>0)?(offSet/2):0;
        $('#courseShow').css({
            'margin-left':0,
            'margin-top': '0px'
        });
        $('.paint_list').css({
            'width':$('#courseShow').width(),
            'height':$('#courseShow').height(),
            'top':0,
            'left':$('#courseShow').css('margin-left')
        });
        var canvas=document.getElementById('paint_canvas');
        canvas.width=$('#courseShow').width();
        canvas.height=$('#courseShow').height();
        paint.updateData();
    }
});
define('zTouch',function (require, exports, module) {
    function Swipe(tBox,args) {
        var tPoint={
            self:tBox,
            count:0,
            speed:300,
            iniL:30,
            iniT:30,
            iniAngle:30,
            touch:false,
            touchStart:false,
            mutiTouch:false,
            setAttr:function(name,value){
                tPoint[name]=value;
            },
        };
        function reinitData(){
            _this=tPoint.self;
            for(var o in args){
                tPoint[o]=args[o];
            }
            var _offset=_this.offset();
            tPoint.bL=_offset.left;
            tPoint.bT=_offset.top;
            tPoint.bW=_this.width();
            tPoint.bH=_this.height();
            tPoint.bRb=tPoint.bL+tPoint.bW; //右边界
            tPoint.bBb=tPoint.bT+tPoint.bH; //下边界
            tPoint.total=_this.children().children().length;
        }
        // init初始化
        reinitData();

        // 浏览器特性检测
        tPoint.vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' :
            (/firefox/i).test(navigator.userAgent) ? 'Moz' :
                'opera' in window ? 'O' : '';
        tPoint.has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix();
        tPoint.hasTouch = 'ontouchstart' in window;
        tPoint.hasTransform = tPoint.vendor + 'Transform' in document.documentElement.style;

        // 方向检测(左移距离，上移距离)
        function directionDetect(l,t){
            if(Math.abs(t)<tPoint.iniT&&Math.abs(l)>tPoint.iniL){
                var rStr=l<0?'left':'right';
                return rStr;
            }
            return false;
        }

        // 边界检测
        function borderDetect(x,y){
            return (x<tPoint.bL||x>tPoint.bRb||y<tPoint.bT||y>tPoint.bBb);
        }

        // 获取夹角(通过arctant反三角函数)
        function getAngle(n){
            return Math.atan(n)*180/Math.PI;
        }

        // 获取距离(通过两边计算第三边)
        function getDis(xLen,yLen){
            return Math.sqrt(Math.pow(xLen,2)+Math.pow(yLen,2));
        }

        // 设置tPoint的改变数据（默认设置改变数据，如果setList存在，则遍历setList设置属性）
        function setPointData(point,setList){
            if(setList){
                for(var o in setList){
                    tPoint.setAttr(o,setList[o]);
                }
            }else{
                var t = new Date();
                tPoint.endX=point.pageX;
                tPoint.endY=point.pageY;
                tPoint.endTime=t.getTime();
                tPoint.duration=tPoint.endTime-tPoint.startTime;
                tPoint.mX=point.pageX-tPoint.startX;//滑动距离
                tPoint.mY=point.pageY-tPoint.startY;
                tPoint.direction=directionDetect(tPoint.mX,tPoint.mY);
                tPoint.angle=getAngle(tPoint.mY/tPoint.mX);
            }
        }

        // 多点触摸检测(只检测单点和两点触摸)
        function multiTouchDetect(e){
            tPoint.tLen=e.touches.length;
            if(tPoint.tLen>1){
                var point0=e.touches[0],
                    point1=e.touches[1],
                    xLen=point1.pageX-point0.pageX,
                    yLen=point1.pageY-point0.pageY,
                    angle=getAngle(yLen/xLen),
                    gDis=getDis(xLen,yLen);
                if(!tPoint.mutiTouch){
                    tPoint.gStartDis=gDis;
                    tPoint.gStartAngle=angle;
                }else{
                    tPoint.gEndDis=gDis;
                    tPoint.gEndAngle=angle;
                    tPoint.scale=gDis/tPoint.gStartDis;
                    tPoint.rotation=angle-tPoint.gStartAngle;
                }
                tPoint.mutiTouch=true;
            }else{
                var point0=e.touches[0],
                    xLen=point0.pageX-tPoint.startX,
                    yLen=point0.pageY-tPoint.startY;
                tPoint.xLen=xLen;
                tPoint.yLen=yLen;
                tPoint.mutiTouch=false;
            };
        }

        function startFun(e){
            var point = e.touches[0],
                t = new Date();
            reinitData();
            var setList={
                startX:point.pageX,
                startY:point.pageY,
                startTime:t.getTime(),
                identifier:point.identifier,
                startLeft:parseInt(tPoint.self.css('left').replace('px','')),
                startTop:parseInt(tPoint.self.css('top').replace('px',''))
            }
            setPointData(point,setList);
            tPoint.touch=true;
            if(typeof tPoint.sCallback=="function"){
                tPoint.sCallback(tPoint);
            }
            tPoint.touchStart=true;
            e.preventDefault();
        }

        function moveFun(e){
            if(tPoint.touchStart){
                var point = e.touches[0];
                if(borderDetect(point.pageX,point.pageY)){
                    tPoint.touch=false;
                    return false;
                }
                if(tPoint.touch){
                    setPointData(point);
                    multiTouchDetect(e);// Muti touch detect
                    if(typeof tPoint.mCallback=="function"){
                        tPoint.mCallback(tPoint,e);
                    }
                }
                if(Math.abs(tPoint.angle)<tPoint.iniAngle){
                    e.preventDefault();
                }
            }
        }

        function endFun(e){
            if(tPoint.touchStart){
                tPoint.touch=false;
                tPoint.mutiTouch=false;
                if(typeof tPoint.eCallback=="function"){
                    tPoint.eCallback(tPoint);
                }
                tPoint.touchStart=false;
            }
        }

        // 实例化之前的回调函数
        if(typeof tPoint.beforeCallback=="function"){
            tPoint.beforeCallback(tPoint);
        }

        // Touch事件监听
        _this.die("touchstart,touchmove,touchend");
        _this.get(0).addEventListener('touchstart',startFun);
        _this.get(0).addEventListener('touchmove',moveFun);
        _this.get(0).addEventListener('touchend',endFun);

        // 实例化之后的回调函数
        if(typeof tPoint.afterCallback=="function"){
            tPoint.afterCallback(tPoint);
        }
    }
    exports.bindSwiper= function () {
        if (window.jQuery || window.Zepto) {
            (function(a) {
                a.fn.Swipe = function(b) {
                    return this.each(function() {
                        a(this).data("Swipe", new Swipe(a(this), b))
                    })
                }
            })(window.jQuery || window.Zepto)
        };
    }
});
define("shareWeixin",function (require, exports, module) {

    var fixurl = window.location.host;
    var imgUrl = "http://"+fixurl+common.imgUrl+"shareIco.png";

    var lineLink = document.URL;
    var descContent = "想要全球Walk，请来51Talk！名师公开课就要开始啦，上课戳这里哦~";
    var shareTitle = $("#courseTitle").val();
    var appid = $("#appIdHid").val();

    //点击微信自带的分享的操作
    exports.shareweixin= function () {

        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: appid, // 必填，公众号的唯一标识
            timestamp: $("#timestampHid").val(), // 必填，生成签名的时间戳
            nonceStr: $("#nonceStrHid").val(), // 必填，生成签名的随机串
            signature: $("#signatureHid").val(),// 必填，签名
            jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表
        });

        wx.ready(function () {

            //分享到朋友圈
            wx.onMenuShareTimeline({
                title: shareTitle, // 分享标题
                link: lineLink, // 分享链接
                imgUrl: imgUrl, // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数

                    recordShare();
                },
                cancel: function () {

                    // 用户取消分享后执行的回调函数
                }
            });

            //分享给好友
            wx.onMenuShareAppMessage({
                title: shareTitle, // 分享标题
                desc: descContent, // 分享描述
                link: lineLink, // 分享链接
                imgUrl: imgUrl, // 分享图标
                type: '', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数

                    recordShare();
                },
                cancel: function () {

                    // 用户取消分享后执行的回调函数
                }
            });

            //判断网络类型
            wx.getNetworkType({
                success: function (res) {
                    var networkType = res.networkType; // 返回网络类型2g，3g，4g，wifi

                }
            });
        })
    }

    //显示微信分享时的蒙层
    exports.showcanglike = function () {

        if($("#weiMask").css("display") == "none") return;

        if(common.isLandOrPort() == "landscape") {

            var rig = $(window).width() * 3;
            $("#weiMask img").css("right",rig+"px");

        } else {

            $("#weiMask img").css("right","0px");
        }

    }

    function showWeiMask(classname,imgstr){

        if(common.isLandOrPort() == "landscape") {
            var rig = $(window).width() * 3;
            var str =  "<img class='"+classname+"' style='right:"+rig+"px' src='"+imgstr+"'>";
        } else {
            var str =  "<img class='"+classname+"' src='"+imgstr+"'>";
        }

        $("#weiMask").append(str);

        $("#weiMask").show();
    }

    //分享成功后的后台统计
    function recordShare() {

        var courseId = $("#courseIDHid").val();

        var submitUrl = "http://www.51talk.com/Thirdparty/Wxsub/record_share";
        $.ajax({
            url: submitUrl,
            type: "POST",
            data: {
                course_id: courseId,
                page_type: "Class",
                channel: $("#qudaoHid").val()
            },
            success: function (info) {

                var result = info;

                if (result == "1") {

                    console.log("统计成功")

                } else {

                    return ""
                }

            }
        })
    }
    // 直播页收藏和分享按钮操作
    exports.weicanglike = function () {
        // 收藏

        $("#heartBtn").click(function () {

            showWeiMask("wx_cc", common.imgUrl+"shoucang.png")

        })

        //分享
        $("#shareBtn").click(function () {

            showWeiMask("wx_fx", common.imgUrl+"share.png")

        })

        $("#weiMask").click(function(){
            $(this).hide()
                .html("");
        })
    }
});
define("simpScroller",function (require, exports, module) {

        // 根据是否支持touch方法确定事件的类型
        var _upSupportTouch = !((window.DocumentTouch && document instanceof window.DocumentTouch) || 'ontouchstart' in window) * 1
            , _event = {
            start: ["touchstart", "mousedown"][_upSupportTouch],
            move: ["touchmove", "mousemove"][_upSupportTouch],
            end: ["touchend", "mouseup"][_upSupportTouch]
        };

        // 滚动
        var _scroller = function (container, direction, params) {
            var key = "top", Key = "Top", size = "height", Size = "Height", pageKey = "pageY";
            if (direction == "horizontal") {
                key = "left";
                Key = "Left"
                size = "width";
                Size = "Width"
                pageKey = "pageX";
            }


            // 插入滚动条
            var scroller = null;
            if (params.hideScrollBar == false) {
                scroller = document.createElement("div");
                scroller.className = "scroller_" + direction;
                params.container.appendChild(scroller);
            }

            // 容器尺寸以及包含滚动的尺寸
            var sizeContainer = container["client" + Size]
            // 因为有滚动动态加载等情况出现，因此默认为0
                , sizeContainerWithScroll = 0;

            // 滚动条位置定位方法
            var fnPosScroll = function () {
                if (scroller == null) return;
                var sizeScroller = scroller.style[size].replace("px", "")
                    , keyScroller = container["scroll" + Key] / (sizeContainerWithScroll - sizeContainer) * (sizeContainer - sizeScroller);

                // 边界溢出的修正
                if (sizeContainer - sizeScroller - keyScroller <= 0) {
                    keyScroller = sizeContainer - sizeScroller;
                }
                // 滚动条的定位
                scroller.style[key] = keyScroller + "px";
            };

            // 事件
            var pos = {};
            container.addEventListener(_event.start, function (event) {
                sizeContainerWithScroll = this["scroll" + Size];
                pos[pageKey] = event.touches ? event.touches[0][pageKey] : event[pageKey];
                pos[key] = this["scroll" + Key];
                document.moveFollow = true;
                if (scroller && sizeContainerWithScroll > sizeContainer) {
                    scroller.style.opacity = 1;
                    scroller.style[size] = (sizeContainer * sizeContainer / sizeContainerWithScroll) + "px";

                    fnPosScroll();
                }
                _upSupportTouch && event.preventDefault();
            });
            container.addEventListener(_event.move, function (event) {
                if (!_upSupportTouch || document.moveFollow) {
                    // touch设备或有可移动标志
                    this["scroll" + Key] = pos[key] + (pos[pageKey] - (event.touches ? event.touches[0][pageKey] : event[pageKey]));
                    // 自定义滚动条的位置
                    fnPosScroll();
                    // 回调
                    params.onScroll.call(this, event);
                }
                // 阻止默认滚动
                event.preventDefault();
            });
            container.addEventListener(_event.end, function (event) {
                scroller && (scroller.style.opacity = 0);
            });

            if (_upSupportTouch) {
                document.addEventListener("mouseup", function () {
                    this.moveFollow = false;
                });
            }
        };

        // 滚动方法
        exports.simpscroller= function (container, options) {

            options = options || {};
            // 确定参数
            var params = new Object({
                verticalScroll: true,
                horizontalScroll: false,
                hideScrollBar: false,
                onScroll: function () {
                }
            }), key;
            for (key in options) {
                params[key] = options[key];
            }

            if (window.getComputedStyle(container).position == "static") {
                container.style.position = "relative";
            }

            // 子元素们
            var childerns = container.childNodes
            // 文档片段
                , fragment = document.createDocumentFragment();

            // 将子元素的集合放在文档片段中
            // 方便实现wrap效果
            [].slice.call(childerns).forEach(function (child) {
                fragment.appendChild(child);
            });

            // wrap的父元素
            var wrap = document.createElement("div");
            wrap.style.height = "100%";
            wrap.style.width = "100%";
            wrap.style.overflow = "hidden";

            // 容器插入包裹元素
            container.appendChild(wrap);
            // 加载子元素集合文档片段，完成wrap包裹效果
            wrap.appendChild(fragment);
            params.container = container;

            if (params.verticalScroll == true) {
                _scroller(wrap, "vertical", params);
            }
            if (params.horizontalScroll == true) {
                _scroller(wrap, "horizontal", params);
            }
        };

})

$(document).ready(function () {

    //加载模块：登录，初始化操作

    common.getUserInfo();

    var appVerStr = common.getAppVersion();
    var osP = appVerStr.indexOf("OS") + 2;
    var lineP = appVerStr.indexOf("_");
    var verNum = appVerStr.substring(osP,lineP);
    console.log("版本号：%s",verNum);
    seajs.use(["comm_server", "chat", "paintWeb", "userSlide", "handShake", "shareWeixin"], function (commonServer, chat, paintWeb, userSlides, handShake, shareWeixin) {

        //登录（连接socket）
        commonServer.comm_login();

        //初始化聊天
        chat.eventBind();

        //初始化教材
        paintWeb.initBind();

        //教材和讨论区的旋转效果
        userSlides.transformPages();

        //整个页面的横屏下的翻页效果
        userSlides.pageSlides();

        //监听屏幕横屏情况下的touch事件
        userSlides.windowListenerSizes();

        //教材的放大和缩小
        userSlides.zoomPages();

        //微信分享出去
        shareWeixin.shareweixin();
        //微信分享时显示的蒙层
        shareWeixin.weicanglike();

    })

})

//从金山调用的关闭音视频的操作
function closeVoice() {
    //视频
    if(document.getElementById("videoBox")){
        document.getElementById("videoBox").currentTime = 0;
        document.getElementById("videoBox").pause();
    }
    //音频
    if(document.getElementById("audioBox")){
        document.getElementById("audioBox").currentTime = 0;
        document.getElementById("audioBox").pause();
    }

}
